Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Greg Freeman:
Processing data with PHP using STDIN and Piping
Nov 18, 2013 @ 16:24:56

Greg Freeman has a post today looking at using streams and STDIN in PHP to handling incoming data (like to a CLI script).

PHP streams are still lacking in documentation and are rarely used compared to other PHP features. This is a shame because they can be really powerful and I have used them to gain a lot of performance when doing things such as processing log files. One of the more powerful features of Linux is the ability to pipe in data from another program, it’s often faster to offload tasks to an existing linux user space program than to do it in PHP and the added benefit is that you gain multi core processing which is not possible with standard PHP.

He talks briefly about the "pipe" character and how it allows you to send the output from one command to another. He shows how to mimic this same kind of input handling in PHP using the "php://stdin" stream and a fopen function call. He gets a bit more in-depth into how the streams work (blocking) and a bit of configuration and data you can get about the current streams. The post finishes with an example of a non-blocking input handler that will automatically end execution if no data is given within three seconds.

tagged: data process stdin input handling tutorial pipe

Link: http://www.gregfreeman.org/2013/processing-data-with-php-using-stdin-and-piping/

Joshua Thijssen:
PHP’s Resources and garbage collection
Jul 12, 2013 @ 15:54:34

Joshua Thijssen has put together a new post with details about garbage collection in PHP and a "nice bug/feature/whatsmathing" he found related to it and its performance.

I was playing around with writing a daemon and if you have any experience writing daemons (in any language), there are a few rules you have to live by. For instance, setting your effective uid and gid to a non-privileged user (in case you needed to do some privileged initialization, like opening a socket on a tcp port < 1024), setting the process as a group leader with posix_setsid(), and redirecting stdio file descriptions. And here something went wrong which took a while to find and fix..

He was creating a daemon and the script would just exit without a warning and not continue running. He narrowed down the issue to a few lines (with fopen and fclose) and went to debug it with strace to really see what was happening. He found some unexpected calls in the stack trace and, after some more digging, finally figured out it was a problem of both scope and cleanup that was resulting in the extra calls.

tagged: garbage collection resource stdin stdout stderr bug

Link: http://www.adayinthelifeof.nl/2013/07/10/phps-resources-and-garbage-collection

PHPBuilder.com:
PHP and Shell Scripting: Using Pipes
Feb 13, 2009 @ 13:51:52

On PHPBuilder.com today there's a new tutorial that takes a deeper look at shell scripting (continuing on from a previous article) with a focus on pipes and their use in simple PHP shell scripts.

This article covers some advanced uses of the language and shows some tricks that make PHP an extremely useful language to work with. Unlike Darrel's article [here] however, this one will also cover the Windows version of PHP as well as the Linux/Unix one.

They compare the two operating environments, noting what can and can't be done in each before getting to some of the "neat things" that pipes let you do. They show who to read from stdin (making it easy to pass the results from another command in) and what you can do with the results. Near the end there's also a bit included showing how to do a similar thing on windows (with the help of an external tool).

tagged: pipes tutorial linux windows compare powertools stdin

Link:

PHP.net:
PHP 5.1.6 Released
Aug 24, 2006 @ 16:25:20

On the main PHP site there's a note about the latest release of the language - PHP 5.1.6.

The PHP development team would like to announce the immediate availability of PHP 5.1.6. This release contains a fix for memory_limit restriction on 64 bit systems that was not included in PHP 5.1.5.

They also corrected this bug, an issue with the "php://stdin" (and the like) functionality that caused crashes on Windows systems.

You can grab this latest update from the Downloads page in both the source and Windows binaries distributions.

tagged: release php5.1.6 memory_limit stdin windows crash release php5.1.6 memory_limit stdin windows crash

Link:

PHP.net:
PHP 5.1.6 Released
Aug 24, 2006 @ 16:25:20

On the main PHP site there's a note about the latest release of the language - PHP 5.1.6.

The PHP development team would like to announce the immediate availability of PHP 5.1.6. This release contains a fix for memory_limit restriction on 64 bit systems that was not included in PHP 5.1.5.

They also corrected this bug, an issue with the "php://stdin" (and the like) functionality that caused crashes on Windows systems.

You can grab this latest update from the Downloads page in both the source and Windows binaries distributions.

tagged: release php5.1.6 memory_limit stdin windows crash release php5.1.6 memory_limit stdin windows crash

Link:


Trending Topics: