SPB Mobile Shell PHP reads the content that the shell pipeline transmits over

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

  • Related Article

    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.