News 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

DevShed: A Quick Overview of the XML DOM Extension in PHP 5

PHP-Security.net: X.509 PKI login with PHP and Apache

Jonathan Snook's Blog: Easier Static Pages for CakePHP 1.2 Update

ServerGrove Blog: Spooling emails with Symfony2 on VPS and Shared Hosting

O\'Reilly: Improve Your Build Process with Ant


Community Events

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


library part2 application symfony2 podcast performance voicesoftheelephpant api series php7 introduction release laravel framework community configure conference example interview opinion

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