PHP Language Implementation script asynchronous execution _php tutorial

Source: Internet
Author: User

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

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