PHP implementation script asynchronous execution _ PHP Tutorial

Source: Internet
Author: User
PHP implements asynchronous execution of scripts. The PHP language uses the fsockopen () function to implement asynchronous script execution. the following code is an asynchronous request function (debugging is used if the debug parameter is true, enabling debugging allows PHP to implement asynchronous script execution
The php language uses the fsockopen () function to implement asynchronous script running. the code is as follows:

// Asynchronous request function (if the debug parameter is true, debugging is used. enabling debugging can display asynchronous execution, but the asynchronous effect is lost)

Main. php

 $ V) {$ _ post [] = $ k. "= ". urlencode ($ v); // url transcoding is required to prevent confusion of post parameter key-value pairs due to the presence of & characters in the data submitted by simulating post.} $ _ post = implode ('&', $ _ post); $ header. = "Content-Type: application/x-www-form-urlencoded \ r \ n"; // POST data $ header. = "Content-Length :". strlen ($ _ post ). "\ r \ n"; // The length of the POST Data $ header. = "Connection: Close \ r \ n"; // The persistent Connection is closed $ header. =$ _ post; // transmits POST data} else {$ header. = "Connection: Close \ r \ n"; // Long Connection closed} fwrite ($ fp, $ header ); // ----------------- Debugging code interval ----------------- // if the following annotation is enabled, asynchronous debugging will not take effect, but if ($ debug) {$ html = ''; while (! Feof ($ fp) {$ html. = fgets ($ fp);} echo $ html;} // ----------------- debug code interval ------------------- fclose ($ fp );} $ data = array ('name' => 'guoyu', 'pwd' => '000000'); $ url = 'http: // localhost/test/other. php '; request_by_fsockopen ($ url, $ data, true );//

Other. php

 


Instance used:
[Main. php main script file running]
$ Data = array ('name' => 'guoyu', 'pwd' => '123 ');
$ Url = 'http: // localhost/test/other. php ';
Request_by_fsockopen ($ url, $ data, true); // asynchronously synchronizes data from the user table of Application B.

[Export step execution file other. php]
In other. php, you can use $ _ POST to receive parameters submitted by main. php and perform the next step.

The fsockopen () function is used in the scripting php language to implement asynchronous script running. the code is as follows // asynchronous request function (if the debug parameter is true, debugging is used. you can enable debugging...

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.