2013年5月31日星期五

Site News: Popular Posts for the Week of 05.31.2013

Popular posts from PHPDeveloper.org for the past week:

Community News: Packagist Latest Releases for 05.31.2013

Recent releases from the Packagist:

Brandon Savage: Consuming RabbitMQ messages with PHP


Brandon Savage continues his look at using RabbitMQ and PHP together to queue up requests today in this latest post. In this new part of the series, he focuses on the last piece of the puzzle - consuming the requests in the queue. (Parts one and two)



Once you've created a RabbitMQ producer, it's fairly easy to create a consumer. In fact, the only difference is in exactly what commands you're using. The connection, envelope, channel and queue declarations are the same. While in RabbitMQ you publish to the exchange, you actually do consume a specific queue. As a result, the commands for consuming are part of the AMQPQueue class.


He shows you how to set up the code to sit in the background and wait for a queue request and how to fetch them in a non-blocking way. He finishes off the post with a look at handling success and error conditions (based on the status of message consumption, not the result of the processing).


Link: http://www.brandonsavage.net/consuming-rabbitmq-messages-with-php

Community News: Laravel 4 Stable Released


The long-awaited versino 4 of the Laravel Framework has finally been released (and the site has gotten a facelift as well):




Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, and caching.



Laravel aims to make the development process a pleasing one for the developer without sacrificing application functionality. Happy developers make the best code.




You can find lots of information about the framework and its functionality on the main project site including a forums area with lots of discussion around not only v4 but still v3 for those using it. You can also find some good discussion about the release itself in this thread over on Reddit.


Link: http://laravel.com/four

Rasmus Larsson: Building a template engine in PHP


Rasmus Larsson has a recent post to his site showing how to build a basic templating engine in PHP that uses the "__toString" to help render the result.



Possibly the most common sign of bad code is tight coupling, especially between logic and presentation. It might seem like a good idea to print out the HTML while the data is being generated, but it more often than not leads to a big incoherent mess of tangled code. [...] While PHP makes it unnecessarily easy to write shitty code it also provides a lot of ways to avoid it. I'll use this post to show you how ridiculously easy it is to create a template engine in PHP in three easy steps.


He includes the sample code for a "Template" class and shows the combination of exporting variables and output buffering to return the resulting template populated with values. The "__toString" method makes it so that you can just echo out the object and get the results.


Link: http://www.rasmuslarsson.se/2013/05/a-template-engine-in-php

2013年5月30日星期四

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

Here's what was popular in the PHP community one year ago today:

Community News: Packagist Latest Releases for 05.30.2013

Recent releases from the Packagist:

PHPMaster.com: Create Digital Tickets with PHP and Apple Passbook


On PHPMaster.com today there's a new tutorial showing you how to create digital tickets using PHP and the Apple Passbook service.



Why should we PHP warriors care at all about Apple's Passbook? Well first because Apple made this technology open (well, sort of…), second because it can be used outside iOS devices, and third because it involves a lot of well-known and loved technologies like JSON and RESTful APIs. I'd also add that it's a very interesting piece of technology, but that's my personal opinion. In this article I'll show you how I built a sample web application that creates and distributes passes in the form of a "PHPMaster Membership Card". It is not a full-featured product, but it's a nice base to build on for more serious real world uses.


He talks about the concept of a "pass" (a digitally signed document that can be easily distributed) and the types that the Apple service lets you make. His example (sample code here) is Silm based and Idorim & Paris for the data handling. He talks some about the certificate handling that's involved and the structure of the application including the certs, application code, templates and images. He then works through the code step-by-step and explains what each part does and how it connects with Apple's service to generate the pass.


Link: http://phpmaster.com/create-digital-tickets-with-php-and-apple-passbook

Brandon Savage: Publishing messages to RabbitMQ with PHP


Brandon Savage has posted the second article in his RabbitMQ+PHP series today with a look at publishing messages to the queue. (Part one is here)



Now that we understand the basics behind RabbitMQ, it's time for us to start working with it. The first step in working with RabbitMQ is to begin sending messages to the exchange so that they can be queued. In RabbitMQ parlance, the "producer" is responsible for "publishing" the messages to the exchange.


He includes the code you'll need to use the AMQP PHP extension to connect with the RabbitMQ server and select a channel. He also shows how to set up an "exchange" and "queue" and bind them to each other. Finally, there's the one line of code that uses the routing key value to push a message into the waiting service.


Link: http://www.brandonsavage.net/publishing-messages-to-rabbitmq-with-php

PHPClasses.org: 10 Steps to properly do PHP Bug Tracking and Fixing as Fast as possible


On the PHPClasses.org blog today Manuel Lemos has shared some advice on tracking and fixing bugs and some strategies to help prevent them in the future.



No matter how hard you try to test your PHP applications before putting them in production, you will always ship code to your server that has bugs. Some of those bugs will be very serious and need to be fixed before they cause greater damages to your application data that may be too hard to recover. Read this article to learn about a several good practices that you can apply to track bugs in production code, so you can fix them before it is too late.

Suggestions included in his list are things like:



  • Test as Much as Possible Before in your Development Environment
  • Separate your Code from Environment Configuration files
  • Track PHP Errors with Assertion Condition Tests
  • Send PHP Errors to an Error Log File
  • Monitor the PHP Error Log File to Quickly Fix Serious Bugs
  • Fix Your Bugs but Never Edit Code on the Production Server


He also includes a brief look at some things to think about when considering "defensive coding practices" and links to other articles with more information.


Link: http://www.phpclasses.org/blog/package/1351/post/1-10-Steps-to-properly-do-PHP-Bug-Tracking-and-Fixing-as-Fast-as-possible.html

2013年5月29日星期三

Community News: Latest Releases from PHPClasses.org

Community News: Packagist Latest Releases for 05.29.2013

Recent releases from the Packagist:

MaltBlue.com: Zend Framework 2 - The New HTML5 Form Fields


Matthew Setter has posted another in his series looking at the Zend Framework v2 and some of its features. In this new post he focuses on the HTML5 form field support that comes bundled with recent versions.



In this tutorial, I'll be taking you through a few of the new HTML5-specific form elements available in the new Zend Framework 2. We'll see: how they work, how to use them, so you can also see what they're like. This will be coupled with a good set of screenshots - so you know what they look like. By the end of this tutorial, you should be well on your way to being able to have fully HTML5 interfaces in your applications.


He starts off by talking about HTML5 elements in general, pointing out a few reasons why to use them, complete with statistics to back them up (of mobile usage where HTML5 can be handy). He focuses specifically on four different elements - the telephone input field, email field, URL field and the date/time selector. He gives examples of each and screenshots of what they look like on a mobile device (iPhone in this case). Complete code is included to create the elements as well.


Link: http://www.maltblue.com/tutorial/zf2-html5-form-field-introduction

Timothy Boronczyk: Composing Music with PHP


Timothy Boronczyk has a recent post to his site with an interesting thing to use PHP for - composing music.



I'm not an expert on probability theory, artificial intelligence and machine learning, and even my Music 201 class from years ago has been long forgotten. But if you'll indulge me for the next 10 minutes, I think you'll find that even just a little knowledge can yield impressive results if creatively woven together into an application. I'd like to share with you how PHP can be taught to compose music.


He shows examples of some basic melodies generated by PHP (not the prettiest) and talks about how he "taught" PHP to get better at it. He transcribed other music into Scientific Pitch Notation and used a Markov process to create a "next note selection" method based on the notes around it. He includes the code for his "robot composer" class with its "train" and "compose" methods and and example of its usage.


Link: http://zaemis.blogspot.com/2013/05/composing-music-with-php.html

Codeception.com: Headless Browser Testing with Selenium2 and PhantomJS


On the CodeCeption blog they have an example if how to use the testing tool to run headless with Selenium2 and PhantomJs to work with Javascript or DOM elements in the page.



The latest version of PhantomJS is an easy to install, stand-alone binary that doesn't require installing Node.js or any other dependencies, and ships with its own 'Ghost Driver' for implementing the WebDriver Wire Protocol. Which means you can drive it using the Selenium2 driver in Codeception, and anything that you can test in Chrome, Firefox, Safari, or IE using Selenium2, you can now test in half the time using PhantomJS.


They help you get the tools you need installed and show you how to start up the Selenium server and connect PhantomJS to it. Then you just run the acceptance tests for your application and get some feedback directly in the terminal window from the execution.



Headless testing can be a bit of a challenge, since it's impossible to 'see' what failed. But in this case, Codeceptions default logging and screenshot capture on failure can be extremely helpful, since you can then actually see the state of the browser at the point of failure.

Link: http://codeception.com/05-13-2013/phantom-js-headless-testing.html

2013年5月28日星期二

Community News: Latest PECL Releases for 05.28.2013

Latest PECL Releases:
  • fribidi 1.2
    Requires GNU FriBidi version 0.19.1 or later.


  • libevent 0.1.0
    - Added event_base_reinit(). (Ivan Shalganov, Andy Skelton)
    - Added config.w32. (bruno at chalopin dot fr)
    - Fixed windows compilation with libevent 2.x. (Anatol Belski)
    - Fixed bug #61673 (callback function args are wrong for signal handler).
    - Fixed bug #61653 (Segfault on event_free()).


  • xdebug 2.2.3
    Tue, May 21, 2013 - xdebug 2.2.3

    + Added features:

    - Support for PHP 5.5.

    = Fixed bugs:

    - Fixed bug #923: Xdebug + Netbeans + ext/MongoDB crash on MongoCursor instance
    - Fixed bug #929: Directory name management in xdebug.profiler_output_dir
    - Fixed bug #931: xdebug_str_add does not check for NULL str before calling strlen on it
    - Fixed bug #935: Document the return value from xdebug_get_code_coverage()
    - Fixed bug #947: Newlines converted when html_errors = 0


  • memprof 1.0.0
    PECL release


  • mongo 1.4.0
    ** Improvement
    * [PHP-303] - Support the autoIndexId option for createCollection
    * [PHP-316] - When using replica sets and setSlaveOkay queries slow if a secondary is down...
    * [PHP-371] - Replication connection string hangs for quite some time when a machine that is listed is physically down
    * [PHP-490] - "nolock" option in MongoDB::execute method
    * [PHP-537] - Update limits according to default (16MB) or server info (maxMessageSizeBytes)
    * [PHP-572] - Add support for "journal" and "fsync" connection string options
    * [PHP-610] - Remove the mongo.utf8 setting
    * [PHP-651] - Slow connection to the replica set with one member down
    * [PHP-686] - Constant attempt to reconnect to a down server takes too long
    * [PHP-744] - Support the oplog_replay query flag
    * [PHP-775] - MongoCursor->hint() can't hint on a index by name
    * [PHP-790] - MongoCollection write operation wtimeout option inconsistent with connection string wTimeoutMS option

    ** New Feature
    * [PHP-664] - Add support for SSL and certificate validation

    ** Bug
    * [PHP-296] - Many of the zend_hash_find calls for options etc do not check or convert correctly for datatype issues.
    * [PHP-447] - Inconsistent error for unsupported database commands on mongod and mongos
    * [PHP-508] - Change BSON ID generation to use random "increment"
    * [PHP-554] - MongoId should not get constructed when passing in an invalid ID.
    * [PHP-653] - is_master() failing with mongodb <= 1.8.3
    * [PHP-675] - Test for PHP-511 broken
    * [PHP-693] - MongoCursor timeout not used when reading data
    * [PHP-696] - mongo_io_wait_with_timeout() waits 10 seconds instead of one for "no socket timeout"
    * [PHP-698] - Segmentation Fault - in mongo_deregister_callback_from_connection when calling MongoClient->close()
    * [PHP-704] - Incorrect failure checks for stream reads
    * [PHP-707] - Replication with 1.8 does not work
    * [PHP-715] - Crash in PHP driver on Apache
    * [PHP-717] - (Almost) All tests leak and has a unconditional jump
    * [PHP-718] - ZTS Broken in master
    * [PHP-723] - Possibly invalid read in MongoCollection getter
    * [PHP-731] - Memory leak during failover
    * [PHP-732] - Improve error message during failover
    * [PHP-734] - Possible segfaults when error_message is not set
    * [PHP-735] - Queries/commands to mongos should inherit read preferences from MongoDB and MongoCollection objects
    * [PHP-736] - MongoClient connection fails if RP tags match nothing
    * [PHP-737] - Missing RP tags parse error message using MongoClient options array
    * [PHP-741] - Passive replicaset members (priority=0) not used for secondary reads
    * [PHP-746] - The getBytes method may return random data in particular conditions.
    * [PHP-751] - When a secondary goes into recovery mode, we should disconnect from it
    * [PHP-759] - Write operations apply ReadPreferenceTags when finding primary
    * [PHP-770] - Missing error code for "field names must be strings" MongoException
    * [PHP-776] - MongoCollection::batchInsert() with empty options array segfaults
    * [PHP-779] - Cannot read from secondaries when connecting directly (standalone connection)
    * [PHP-781] - MongoCollection::count() should not leak, and throw exception instead of returning GLE document
    * [PHP-792] - Memory leak while reading an INT64 on a 32bit platform with native_long enabled
    * [PHP-795] - MongoCode segfaults when internal 'code' property is modified
    * [PHP-800] - Error codes for some errors in bson.c are re-used.

    ** Deprecated Functionality
    * [PHP-780] - Deprecate slaveOkay & timeout URI options
    * [PHP-793] - Add deprecation notice to non-array options for MongoDB::createCollection
    * [PHP-801] - Deprecate boolean options to MongoCollection::insert()
    * [PHP-802] - Deprecate boolean options to MongoCollection::ensureIndex()
    * [PHP-805] - Deprecate (for real) the "chunks" option in MongoGridFS::__construc

    ** Task
    * [PHP-314] - Improve connection string documentation/pooling
    * [PHP-437] - Update ZEND_MODULE_API_NO to use PHP_VERSION_ID to be more clear
    * [PHP-475] - Create functional phpt tests for read preference exceptions
    * [PHP-496] - Added a few examples to MongoDB::runCommand() for more examples
    * [PHP-542] - Put all exception classes into their own file(s)
    * [PHP-563] - Strongly advise users not to create immortal MongoCursors
    * [PHP-674] - Remove mention of OSX/Windows GitHub downloads from documentation
    * [PHP-694] - Split out types and gridfs classes into their own files.
    * [PHP-695] - Remove mention of PHPUnit from documentation
    * [PHP-702] - DOC - Support the autoIndexId option for createCollection
    * [PHP-725] - Re-organise option parsing in mcon/parse.c
    * [PHP-738] - Add replica set tags to test suite
    * [PHP-745] - Add Replicaset Tags to sharding test suite
    * [PHP-748] - Add vim modelines
    * [PHP-749] - Improve fragile checks for max_message_size in tests
    * [PHP-767] - Create prototypes for GridFS classes
    * [PHP-768] - Create prototypes for MongoCollection class
    * [PHP-771] - Time expectations mongo.is_master_interval test are fragile
    * [PHP-788] - Document journal/fsync MongoClient connection options
    * [PHP-789] - Document fsync, j, and wtimeout options for MongoCollection write operations


Community News: Packagist Latest Releases for 05.28.2013

Recent releases from the Packagist:

Brandon Savage: Queuing with RabbitMQ and PHP


Brandon Savage has posted a quick overview of working with PHP and RabbitMQ for queuing. This is the first part of a three-part series about using these two technologies together effectively.



There are many times that you want to write background processes and queue up the tasks so that they can be handled in sequential order. There are any number of queues available for software developers, and one that I've really taken a liking to is RabbitMQ. Besides the fact that the queue is designed to requeue messages that are unsuccessfully delivered, RabbitMQ is fast and efficient.


He introduces some of the basic concepts behind working with RabbitMQ (like connections and channels) and an "exchange" - the method by which messages are routed. He talks about pushing messages to the exchange to be handled and how you consume the queue for updates. He also links to the various things you'll need to install to start combining these two tools including the AMPQ PECL extension.


Link: http://www.brandonsavage.net/queuing-with-rabbitmq-and-php

2013年5月27日星期一

Community News: Latest PEAR Releases for 05.27.2013

Latest PEAR Releases:

Community News: Packagist Latest Releases for 05.27.2013

Recent releases from the Packagist:

2013年5月26日星期日

Community News: Packagist Latest Releases for 05.26.2013

Recent releases from the Packagist:

2013年5月25日星期六

Community News: Packagist Latest Releases for 05.25.2013

Recent releases from the Packagist:

2013年5月24日星期五

Site News: Popular Posts for the Week of 05.24.2013

Popular posts from PHPDeveloper.org for the past week:

Community News: Packagist Latest Releases for 05.24.2013

Recent releases from the Packagist:

PHP.net: PHP 5.5.0RC2 is available


On PHP.net today they've announced the release of the latest Release Candidate in the PHP 5.5.x series - PHP 5.5.0RC2.



The PHP development team announces the availability of the second release candidate of PHP 5.5. This release fixes some bugs against RC1 and improves overall stability. [...] Please help us to identify bugs in order to ensure that the release is solid and all things behave as expected. Please test this release candidate against your code base and report any problems that you encounter to the QA mailing list and/or the PHP bug tracker.


Issues corrected include a segfault when memory was used up, an issue with mbstring in PHPT tests in Windows x64 and a problem with custom exceptions. You can find the full list of changes in the NEWS file. Please download this latest release candidate (Windows here) and test it out on your systems.


Link: http://php.net/index.php#id2013-05-23-1

Michelangelo van Dam: UA Testing with Selenium and PHPUnit


In this new post to his site Michaelangelo van Dam looks at user acceptance testing with PHPUnit and Selenium.



Last week I spoke at php[tek] 2013 where I explained to people how to get started with Selenium IDE to record user interaction with the web interface, convert them to PHPUnit testcases and automatically execute them on multiple browsers on multiple platforms. The feedback I got was awesome, you're all a great crowd! But on twitter I also received a bunch of questions regarding how to set up multiple platforms and why I used Windows in my presentation to deploy to. So today I deceided it was time to write a full article on this subject.


He introduces Selenium and what kinds of things it can be used to test. He also defines "user acceptance testing" and talks about why they're an important part of the testing ecosystem. He then walks you through the process of getting the testing environment set up, creating a few tests and how to convert them over to PHPUnit tests (using a built-in tool). Screencasts show you each step of the way. He includes a little tweaking you'll need to do to to the test code to get it working with your own Selenium server


Link: http://www.dragonbe.com/2013/05/ua-testing-with-selenium-and-phpunit.html

Adam Culp: PHP usage statistics


Adam Culp has posted his own look at some of the PHP usage statistics that are out there and how they can be interpreted.



Every once in awhile I stumble across someone who is trying to find their way and decide what they will do in their career. As the organizer of a PHP user group I see many new developers passing through. Of course I always speak of how strong PHP is in the web markets, and encourage new web developers to pursue PHP as a tool in their box of goodies. Because as a web developer it would be a career limiting move to not have any knowledge of PHP. Here is why...


He shares a few different sources including w3tech's overall and PHP-specific information (PHP5 specific here) and the current results of the TIOBE index showing language popularity. For each he talks some about what the results mean (and don't mean) and how, if you're a "professional developer" you should, at the least, know PHP - the most dominant language in the web space.


Link: http://www.geekyboy.com/archives/672

2013年5月21日星期二

Community News: Latest PECL Releases for 05.21.2013

Latest PECL Releases:
  • xhprof 0.9.3
    -- Just updating the pecl package to https://github.com/facebook/xhprof/commit/254eb24dcfa763c76c57b472093ebc4b81af2b7d
    -- Request #16544: Mac port for XHProf (svilen spasov)
    -- fix #16574: require/require_once not special cased like include/include_once (kannan)
    -- add a sanity test for sampling mode in xhprof (kannan)
    -- add support to ignore functions (such as call_user_func) during profiling (mike paleczny)
    -- fix #16098: suppress notices due to use of FILE_BINARY (kannan)
    -- add a sanity test for timer (kannan)
    -- fix for compile error on debian linux (russ)


  • fribidi 1.1
    Requires GNU FriBidi version 0.19.1 or later.


  • pq 0.4.0
    * Added pqConverterInterface and pqConnection::setConverter()
    * Added pqResult::desc() and fixed pqStatement::descAsync()
    * Added serializer for input array params


Community News: Packagist Latest Releases for 05.21.2013

Recent releases from the Packagist: