Twilight, Hello!
Rainbird sent you a short message:
has written a lot of background running deamon. With a very handy, but I now want to get the pipeline passed over the content, do not know how to achieve, similar to echo "AAAA" |a.php,a.php how to get echo content, do not know what you have.
Today received a message, the solution of the method for everyone to share:
In fact, the Shell's | It actually represents the standard output of the previous one as the standard input for the latter one. Although the implementation is achieved through pipe,
But you don't need to know the bottom line when you're writing PHP code. You can read it directly as a standard input:
Here is an experimental code:
Copy the Code code as follows:
$fp = fopen ("Php://stdin", "R");
$s = ";
while (!feof ($FP))
{
$s. = Fgets ($fp, 128);
}
Var_dump ($s);
Fclose ($FP);
?>
Test method:
Copy the Code code as follows:
LS-LH | PHP php_read_pipe.php
Rainbird also gives the simpler code:
file_get_contents (' Php://stdin ')
If there is a lot of data to transfer over, in general, is every 4 K transmission once.
Until the transfer is complete. That may not be easy to use:
file_get_contents (' Php://stdin '). In that case, it will always be waiting.
Separate processing words, can, read a certain amount after processing part. Then release a portion of the memory.
For example, I want to traverse all the files. You can handle this.
Find/| PHP php php_read_pipe.php
We will analyze it according to the specific situation.
The above describes what SPB Mobile shell PHP reads from the shell pipeline, including the SPB mobile shell, and wants to help friends who are interested in PHP tutorials.