What about the non-blocking mode of fsockopen? Why does function & nbsp; fsockopen_test () {& nbsp; $ hostname & nbsp ;=& nbsp; 'm. cn '; & nbsp; & n: What about the non-blocking mode of fsockopen? Why is it blocked?
Function fsockopen_test (){
$ Hostname = 'M. cn ';
$ Url = '/test/1. php ';
$ Fp = fsockopen ($ hostname, 80, $ errno, $ errstr, 5 );
If (! $ Fp ){
Echo "$ errstr ($ errno )";
Return false;
}
Stream_set_blocking ($ fp, 0); // The non-blocking mode described in the manual is enabled.
$ Header = "GET $ url HTTP/1.1 \ r \ n ";
$ Header. = "Host: $ hostname \ r \ n ";
$ Header. = "Connection: Close \ r \ n"; // The persistent Connection is closed.
Fwrite ($ fp, $ header );
Fclose ($ fp );
}
Fsockopen_test ();
The code in/test/1. php in the request:
sleep(6);
$fp = fopen ( './data.txt' , 'w' );
fwrite ( $fp ,111);
fclose ( $fp );
Check whether the test/1. php execution is complete on the browser console. Why?
------ Solution --------------------
No problem
echo date('Y-m-d H:i:s'), PHP_EOL;
fsockopen_test();
echo date('Y-m-d H:i:s'), PHP_EOL;
No latency is displayed.