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: Building a Complete Web Searching Class with Yahoo Web Services and PHP 5

Marcelo Gornstein's Blog: Sniffing in PHP using libpcap: Thank you SWIG!

Christian Schaefer's Blog: Using PHP Web Scraper Goutte in a Console Task in a Silex project

Anonwhat: ASCII Art Generator

Lorenzo Alberton's Blog: Navigation Through Paragraphs in an Article


Community Events





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


podcast framework interview unittest list install opinion community code language series threedevsandamaybe laravel developer configure release refactor testing introduction experience

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