Php reads content transmitted from the shell Pipeline _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.