spb mobile shell php reads the content transmitted by the shell pipe

WBOY
Release: 2016-07-29 08:41:58
Original
1050 people have browsed it

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);
?>


Test method:

Copy code The code is as follows:


ls -lh | php php_read_pipe.php


Rainbird also gives a simpler code:
file_get_contents ( 'php://stdin')
If there is a lot of data to be transferred, generally speaking, it is transferred once every 4K.
Until the transfer is completed. That might not be possible simply using:
file_get_contents('php://stdin'). If so, I will always be waiting.
If you process them separately, you can read a certain amount and then process part of it. Then release part of the memory.
For example, I want to loop through all files. It can be handled like this
find / | php php php_read_pipe.php
We will analyze it based on the specific situation.

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template