STDIN in PHP is a blocking operation. Reading the content directly causes blocking. the following code will run until there is data input: $ datastream_get_contents (STDIN); you can operate by declaring stream_set_blocking (STDIN, FALSE): stream_set_blocking (STDIN, FALSE); $ datastream_get_contents (ST)
STDIN in PHP is a blocking operation. Reading the content directly causes blocking. the following code will run until there is data input: $ data = stream_get_contents (STDIN); you can operate by declaring stream_set_blocking (STDIN, FALSE): stream_set_blocking (STDIN, FALSE ); $ data = stream_get_contents (ST
The STDIN of PHP is a blocking operation. Reading the content directly causes blocking. The following code will run until there is data input:
$data = stream_get_contents(STDIN);
You can perform the following operations by declaring stream_set_blocking (STDIN, FALSE:
stream_set_blocking(STDIN, FALSE);$data = stream_get_contents(STDIN);
Running is still not good, in fact this is a Bug, Description: https://bugs.php.net/bug.php? Id = 34972
The test shows that the read/write position of the STDIN file handle can be obtained through the ftell function.
if(ftell(STDIN)===0){ $data = stream_get_contents(STDIN);}
Original article address: PHP Command Line how to judge the input of pipeline data, thanks to the original author for sharing.