Hello, Mu Xia!
rainbird sent you a short message:
I have written a lot of deamon that run in the background. It is very easy to use, but now I want to get the content passed through the pipe, and I don’t know how to achieve it, similar to echo "aaaa" |a .php, a.php how to obtain the content of echo, I wonder if you have any advice.
I received a message today, and I would like to share the solution with you:
In fact, the | of shell actually represents the previous standard. The output serves as the standard input of the latter. Although the implementation is implemented through pipe,
but you don’t need to know the underlying operation when writing PHP code. You can just read it directly as standard input:
The following is an experimental code:
Copy the code The code is as follows:
$fp = fopen("php://stdin", "r");
$s = '';
while (!feof($fp))
{
$s .= fgets($fp, 128);
}
var_dump($s);
fclose($ fp);
?>
Copy code The code is as follows:
ls -lh | php php_read_pipe.php
The above introduces how spb mobile shell php reads the content transmitted by the shell pipeline, including the content of spb mobile shell. I hope it will be helpful to friends who are interested in PHP tutorials.