Php reads the content transmitted from the shell pipeline. Hey, Muxia! Rainbird sent you a short message: many deamon running in the background have been written. it's easy to use, but I want to get the content from the pipeline now. I don't know how to implement Muxia. Hello!
Rainbird sends you a short message:
I have already written a lot of deamon operations in the background. it works well, but I don't know how to implement it if I want to get the content from the pipeline, like echo "aaaa" |. php,. php does not know how to obtain the echo content.
I received a message today to share with you the solution:
In fact, shell | actually represents the previous standard output as the next standard input. Although the implementation is implemented through pipe,
However, you do not need to know the underlying operations when writing php code. You can read it directly as a standard input:
The following is an experiment code:
The code is as follows:
$ Fp = fopen ("php: // stdin", "r ");
$ S = '';
While (! Feof ($ fp ))
{
$ S. = fgets ($ fp, 128 );
}
Var_dump ($ s );
Fclose ($ fp );
?>
Test method:
The code is as follows:
Ls-lh | php php_read_pipe.php
Rainbird also provides simpler code:
File_get_contents ('php: // stdin ')
If a large amount of data is to be transmitted, it is generally transmitted every 4 K.
Until the transfer is completed. It may not be easy to use:
File_get_contents ('php: // stdin '). In this way, you will always be waiting.
For separate processing, you can read a certain amount of post-processing parts. Then release some of the memory.
For example, I want to traverse all files. Yes.
Find/| php php_read_pipe.php
According to the specific situation.
Success! Rainbird sent you a short message: many deamon running in the background have been written. it is quite easy to use, but I want to get the content from the pipeline now. I don't know how to implement it...