Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Archive for Listopad, 2013

Qandidate.com: Setting up XHProf/XHGui profiling with Ansible

Qandidate.com: Setting up XHProf/XHGui profiling with Ansible

On the Qandidate.com blog there’s a new post showing how to set up the PHP profiling tool XHProf/XHGui using Ansible for setup and configuration. Ansible is a radically simple IT orchestration engine that makes your applications and systems easier to deploy.

Once in a while I think about profiling my web applications to see if I can get them to run faster. There are cool tools out there like XHProf and XHGUI to help you do exactly that. And then I remember it took me quite some time to get it all set up… But now that I’ve started using Ansible I decided to document the set up process and share it with you. Today I will walk you through my Ansible role for setting up everything you need for profiling your first PHP script.

He starts with a checklist of things to be sure you have installed first (including XHProf and XHGui) and links to his yml configuration to run a “profiling” command. An example of the result (the XHGui HTML output) is also included.

Link: http://labs.qandidate.com/blog/2013/11/28/setting_up_xhprof_xhgui_profiling_with_ansible/
Source: http://www.phpdeveloper.org/news/20450

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Community News: Packagist Latest Releases for 11.28.2013

Community News: Packagist Latest Releases for 11.28.2013Recent releases from the Packagist:

Source: http://www.phpdeveloper.org/news/20449

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Site News: Blast from the Past – One Year Ago in PHP

Site News: Blast from the Past – One Year Ago in PHPHere’s what was popular in the PHP community one year ago today:

Source: http://www.phpdeveloper.org/news/20448

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

MaltBlue.com: Are TableGateways Worth it in Zend Framework 2?

MaltBlue.com: Are TableGateways Worth it in Zend Framework 2?

On his MaltBlue.com blog Matthew Setter shares his opinion on TableGateways in Zend Framework v2 and wonders if they’re “worth it” (as they’re not the easiest thing to implement).

Are TableGateways too hard to implement in Zend Framework 2? Are they too hard to justify the effort? That’s what I was asked recently during a Twitter conversation. For me, they’re not. For me, they’re well worth the effort. So I’ve written this post to show why they’re not, and how they bring great flexibility, when implemented correctly. In [this post] I’ll set out why they can be a good solution, as well as why not.

He starts from the origins of PHP scripts, back when they were “a collection of files” and not structured under much of a framework. Complexity added the need for this structure, though, including things like design patterns for common tasks. The TableGateway was one of these. He talks briefly about implementing them in Zend Framework v2 (with some gist examples) and some questions to ask helping you determine if they’re “too much” for you app.

Link: http://www.maltblue.com/patterns/why-tablegateways
Source: http://www.phpdeveloper.org/news/20447

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

PHPBuilder.com: Implementing Automatic Database Backup and Optimization in PHP

PHPBuilder.com: Implementing Automatic Database Backup and Optimization in PHP

On PHPBuilder.com today they have a new article posted sharing a few different methods you can use to do backups of your (MySQL) database and a few handy tricks/tools you can use to optimize it as well.

Every computer system has a backup. Nevertheless, the number of problems caused by a lack of a recent backup is huge. One of the reasons for that may be the fact that the backup process is not entirely automated. So, let’s see how to automate the database backup process in PHP.

There’s three recommendations for the (simple) database backup that can produce a file of the current database contents – mysqldump, mysqlhostcopy and a “SELECT INTO OUTFILE” statement. On the optimization size they suggest mysqlcheck, an OPTIMIZE query to help find trouble spots. There’s a script included at the end showing how these methods can be combined into a simple PHP script, something that can easily be dropped into a cron job to perform every so often.

Link: http://www.phpbuilder.com/articles/databases/mysql/implementing-automatic-database-backup-and-optimization-in-php.html
Source: http://www.phpdeveloper.org/news/20446

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Ben Ramsey: The Fall of PEAR and the Rise of Composer

Ben Ramsey: The Fall of PEAR and the Rise of Composer

Ben Ramsey has an interesting post to his site today looking at what he calls the Fall of PEAR and the rise of Composer when it comes to package management in the PHP community.

PEAR’s biggest selling-point -the curation of packages by a governed community – was also its biggest problem. There was no choice, and things moved slowly. If a package stagnated in development, I couldn’t find another actively supported one to solve the same need. In theory, the maintenance of the package could be taken over by someone else, but this didn’t always happen, and contributing patches was not clear or easy.

Ben talks about how, despite the PEAR development’s best efforts, the proposed new package manager (Pyrus and PEAR2) couldn’t keep up. Then, from a discussion had at a conference, the idea of a standards group was formed, the PHP-FIG, and the first standard soon followed, PSR-0 for autoloading. With this in hand and becoming widely adopted, a new tool was created to make it easier to share and install packages with this new standard – Composer.

Composer is what PEAR should have been. Through Packagist, Composer is the democratization of PHP userland libraries. Many libraries in the repository implement similar functionality, but through a show of popularity, the community self-selects the packages that are of the best quality. [...] In just a few short years, Composer has revitalized the PHP community and changed the way we do development.

Link: http://benramsey.com/blog/2013/11/the-fall-of-pear-and-the-rise-of-composer/
Source: http://www.phpdeveloper.org/news/20445

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Round half to even in Go

Round half to even in Go

Rounding half to even is used a lot when dealing with financial transactions. Here is my implementation in Go:

import "math"

// http://en.wikipedia.org/wiki/Rounding#Round_half_to_even
func roundHalfToEven(f float64) float64 {
        integer, fraction := math.Modf(f)
        f = integer
        if 0.5 == math.Abs(fraction) {
                if 0 != math.Mod(f, 2) {
                        f += math.Copysign(1, integer)
                }
        } else {
                f += math.Copysign(float64(int(fraction+math.Copysign(0.5, fraction))), fraction)
        }
        return f
}

And here are unit tests:

import "testing"

func TestRoundHalfToEven(t *testing.T) {

        testCases := []struct {
                numberToRound  float64
                expectedResult float64
        }{
                {
                        // 23.5 =~ 24
                        numberToRound:  23.5,
                        expectedResult: 24,
                },
                {
                        // 24.5 =~ 24
                        numberToRound:  24.5,
                        expectedResult: 24,
                },
                {
                        // 7.58 =~ 8
                        numberToRound:  7.58,
                        expectedResult: 8,
                },
                {
                        // 7.46 =~ 7
                        numberToRound:  7.46,
                        expectedResult: 7,
                },
                {
                        // 5 =~ 5
                        numberToRound:  5,
                        expectedResult: 5,
                },
                {
                        // -23.5 =! -24
                        numberToRound:  -23.5,
                        expectedResult: -24,
                },
                {
                        // -24.5 =~ -24
                        numberToRound:  -24.5,
                        expectedResult: -24,
                },
                {
                        // -7.58 =~ -8
                        numberToRound:  -7.58,
                        expectedResult: -8,
                },
                {
                        // -7.46 =~ -7
                        numberToRound:  -7.46,
                        expectedResult: -7,
                },
                {
                        // -5 =~ -5
                        numberToRound:  -5,
                        expectedResult: -5,
                },
                {
                        // 0 =~ 0
                        numberToRound:  0,
                        expectedResult: 0,
                },
        }

        for i, tc := range testCases {
                actualResult := roundHalfToEven(tc.numberToRound)
                if actualResult != tc.expectedResult {
                        t.Errorf("%v rounded half to even should be %v, instead of %v (%v)", tc.numberToRound, tc.expectedResult, actualResult, i)
                }
        }

}

Source: http://blog.richardknop.com/2013/11/round-half-to-even-in-go/

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

SitePoint PHP Blog: Social Network Style Posting with PHP, MongoDB and jQuery – part 2

SitePoint PHP Blog: Social Network Style Posting with PHP, MongoDB and jQuery – part 2

The SitePoint PHP blog has posted the second part of their series about the creation of a simple comment posting social site based on PHP, MongoDB and jQuery. In this second part they build on the structure from part one and add in posting and “liking”.

In the previous part of the series, we explained the database architecture, post stream design and application flow required for developing our post mechanism wherein the user will be able to post a status, like/unlike other people’s statuses and comment on them. This part of the series will drive you through the coding required to implement these functionalities. We will use the application flow and database structure as discussed in the last article. Don’t forget to download the code from the github repo if you’d like to follow along.

First he shows you how to get new posts added to the database, POSTed to the backend PHP script. He also shows how to insert the contents back into the page and pull out the latest posts. Next up is the like/unlike-ing of the posts, handled by a simple submission to another backend script.

Link: http://www.sitepoint.com/social-network-style-posting-php-mongodb-jquery-part-2/
Source: http://www.phpdeveloper.org/news/20411

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

SitePoint PHP Blog: Social Network Style Posting with PHP, MongoDB and jQuery – part 2

SitePoint PHP Blog: Social Network Style Posting with PHP, MongoDB and jQuery – part 2

The SitePoint PHP blog has posted the second part of their series about the creation of a simple comment posting social site based on PHP, MongoDB and jQuery. In this second part they build on the structure from part one and add in posting and “liking”.

In the previous part of the series, we explained the database architecture, post stream design and application flow required for developing our post mechanism wherein the user will be able to post a status, like/unlike other people’s statuses and comment on them. This part of the series will drive you through the coding required to implement these functionalities. We will use the application flow and database structure as discussed in the last article. Don’t forget to download the code from the github repo if you’d like to follow along.

First he shows you how to get new posts added to the database, POSTed to the backend PHP script. He also shows how to insert the contents back into the page and pull out the latest posts. Next up is the like/unlike-ing of the posts, handled by a simple submission to another backend script.

Link: http://www.sitepoint.com/social-network-style-posting-php-mongodb-jquery-part-2/
Source: http://www.phpdeveloper.org/news/20411

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Aura Framework Blog: A Peek At Aura v2 — Aura.Router

Aura Framework Blog: A Peek At Aura v2 — Aura.Router

On the Aura Framework blog, they continue their look ahead at the coming version of another of the framework’s components, the Aura v2 Router. The Aura framework is a decoupled, modular framework that focuses on minimizing dependencies.

Lately, we’ve been going over the migration of v2 packages from v1. Today, I’ll talk about the updated Aura.Router v2 package. While not an example of extracting a new package from an existing one, it has a couple of features that other routers don’t currently have, in addition to being truly independent and completely decoupled from any other package.

They focus on some of the basics (more detailed information can be found on the package page) of the package’s new features and its focus on routing rather than dispatching. Sample code is included showing it in use. The examples show basic routing, routing by server values and attaching route groups. There’s also a brief section about adding REST routes via an “attachResource” method call.

Link: http://auraphp.com/blog/2013/11/18/aura-v2-router/
Source: http://www.phpdeveloper.org/news/20410

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>