PHPfsockopen function problem. This script is not blocked and other scripts fail to be triggered.

Source: Internet
Author: User
{Code ...}
$ Host = 'www .abc.com '; $ port = 80; $ query = "admin/mi. php? Key = value "; $ fp = @ fsockopen ($ host, $ port, $ errno, $ errstr, 30); if ($ fp) {$ out =" GET /". $ query. "HTTP/1.1 \ r \ n"; $ out. = "Host :". $ host. "\ r \ n"; $ out. = "Connection: Close \ r \ n"; // 0, the resource stream will be converted to non-blocking mode; 1, the resource stream is converted to the blocking mode. @ Stream_set_blocking ($ fp, 0); @ stream_set_timeout ($ fp, 5); fwrite ($ fp, $ out); // sleep (1 ); // Key location fclose ($ fp);} else {echo "$ errstr ($ errno)
\ N ";}------------- check that SLEEP (1) successfully requested www.abc.com. If no SLEEP (1) request fails, what is the FSOCKOPEN operating mechanism? I don't want to block access to www.abc.com/admin/mi.php in this script. It only needs to trigger the execution of MI. PHP.

Reply content:
$ Host = 'www .abc.com '; $ port = 80; $ query = "admin/mi. php? Key = value "; $ fp = @ fsockopen ($ host, $ port, $ errno, $ errstr, 30); if ($ fp) {$ out =" GET /". $ query. "HTTP/1.1 \ r \ n"; $ out. = "Host :". $ host. "\ r \ n"; $ out. = "Connection: Close \ r \ n"; // 0, the resource stream will be converted to non-blocking mode; 1, the resource stream is converted to the blocking mode. @ Stream_set_blocking ($ fp, 0); @ stream_set_timeout ($ fp, 5); fwrite ($ fp, $ out); // sleep (1 ); // Key location fclose ($ fp);} else {echo "$ errstr ($ errno)
\ N ";}------------- check that SLEEP (1) successfully requested www.abc.com. If no SLEEP (1) request fails, what is the FSOCKOPEN operating mechanism? I don't want to block access to www.abc.com/admin/mi.php in this script. It only needs to trigger the execution of MI. PHP.

Add usleep (1000) to the key point. [latency: 1000 microseconds = 1 millisecond = 0.001 seconds. Currently stable.

--- Cloud network opening

$fpBy youclose. No blocking does not mean that the data can be sent completely. The data sending process is actually quite long. You need to resolve the domain name, establish a link, and wait for the task to be completed.closeThe probability of failure is very high.

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.