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...