PHP Language Implementation script asynchronous execution
The PHP language uses the Fsockopen () function to execute the script asynchronously, the code is as follows
Asynchronous request function (with debug parameter if True is used for debugging, open debugging can see asynchronous execution, but lose the effect of async)
main.php
$v) {$_post[]= $k. " = ". UrlEncode ($v);//must do URL transcoding in case the data in the analog post submission has a & character resulting in the post parameter key value pair disorder} $_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\r\n ";//long connection close $header. = $_post; Pass the Post data}else{$header. = "connection:close\r\n\r\n";//Long Connection Close} fwrite ($fp, $header); -----------------Debug Code Interval-----------------//Note If the following comment is turned on, async will not take effect but it is convenient to debug if ($debug) {$html = '; while (!feof ($fp)) {$html. =fgets ($FP); } Echo $html; }//-----------------debug code interval-----------------fclose ($fp);} $data =array (' name ' = ' Guoyu ', ' pwd ' = ' 123456 '); $url = ' http://localhost/test/other.php '; request_by_fsockopen ($url, $data, true);//
other.php
Usage examples:
[Running main.php main script file]
$data =array (' name ' = ' Guoyu ', ' pwd ' = ' 123456 ');
$url = ' http://localhost/test/other.php ';
Request_by_fsockopen ($url, $data, true);//Use the user table of application B asynchronously-synchronize data
[Lead execution file other.php]
In other.php, you can use $_post to receive main.php submitted parameters for next steps.
http://www.bkjia.com/PHPjc/986702.html www.bkjia.com true http://www.bkjia.com/PHPjc/986702.html techarticle PHP Language Implementation script asynchronous execution PHP language with the Fsockopen () function, the implementation of the script asynchronous run, the code is as follows//asynchronous request function (with the debug parameter if True is used for debugging, open debugging can ... )