What about the non-blocking mode of fsockopen? Why is it blocked?

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

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.