News Feed
Jobs Feed
Sections




News Archive
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
November 18, 2013 @ 10: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.

0 comments voice your opinion now!
data process stdin input handling tutorial pipe

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

blog comments powered by Disqus

Similar Posts

PHPMaster.com: Data Structures for PHP Devs: Trees

Fabien Potencier: Packing a Symfony full-stack Framework Application in one File - Bootstrapping

The Bakery: New Tutorials - PHPTAL, Multiple Checkboxes, and counterCache

PHPBuilder.com: PEAR HTML_Table: Displaying Tabular Data in PHP

Nefarious Designs: Object-Oriented PHP Part 2: Relationships


Community Events











Don't see your event here?
Let us know!


code podcast facebook opinion application language overview hack introduction component symfony2 release install package example security composer unittest framework hhvm

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework