zoukankan      html  css  js  c++  java
  • php异步请求模拟多进程

    在A请求页面发起另一个B页面请求 不需要等待B页面执行结束再返回 直接往下执行A页面的请求

    A页面代码

    <?php
    $url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/send.php";
    $param = array(
        'name'=>'fdipzone',
        'gender'=>'male',
        'age'=>30
    );
    doRequest($url, $param);//发起请求
    function doRequest($url, $param=array())
    {
        $urlinfo = parse_url($url);
        $host = $urlinfo['host'];
        $path = $urlinfo['path'];
        $query = isset($param)? http_build_query($param) : '';
        $port = 80;
        $errno = 0;
        $errstr = '';
        $timeout = 10;
        $fp = fsockopen($host, $port, $errno, $errstr, $timeout);
        $out = "POST ".$path." HTTP/1.1
    ";
        $out .= "host:".$host."
    ";
        $out .= "content-length:".strlen($query)."
    ";
        $out .= "content-type:application/x-www-form-urlencoded
    ";
        $out .= "connection:close
    
    ";
        $out .= $query;
        fputs($fp, $out);
        fclose($fp);
    }
    ?>

    B页面代码

    <?php
    for($i=0;$i<10;$i++)
    {
        sleep(1);
        file_put_contents(time().".txt",time());
    }
    ?>

    然后效果如图:

    然后逐步增加了新文件

  • 相关阅读:
    SRM 441(1-250pt, 1-500pt)
    SRM 387(1-250pt)
    SRM 388(1-250pt)
    SRM 389(1-250pt)
    SRM 601(1-250pt,500pt)
    SRM 409(1-250pt, 1-500pt)
    SRM 408(1-250pt, 1-500pt)
    unique() 去重函数
    poj3468(A Simple Problem with Integers)
    HDU1394(Minimum Inversion Number)
  • 原文地址:https://www.cnblogs.com/lizhaoyao/p/4860989.html
Copyright © 2011-2022 走看看