找回密码
 立即注册
搜索
热搜: 生活 中国

php实现异步请求

[复制链接]
admin 发表于 2020-12-28 00:27:51 | 显示全部楼层 |阅读模式
  1. <?php
  2. //异步请求
  3. $host = "localhost";
  4. $path = '4.php';
  5. $port = 80;
  6. $data = "['email'=>'email@163.com','name'=>'xiaoming']";
  7. $param = http_build_query($data);
  8. $fp = fsockopen($host,$port,$errno,$errstr,30);

  9. if($fp)
  10. {
  11. //post 请求
  12. $header = "POST $path HTTP/1.0\r\n";
  13.    $header .= 'Host:'.$host."\r\n";
  14.     $header .= "Content-Type:application/x-www-form-urlencoded\r\n";
  15.     $header .="Content-Length:".strlen($param)."\r\n";
  16.     $header .= 'Connection:Close'."\r\n\r\n";
  17.     $header .= $param;
  18.      fputs($fp, $header);
  19.     fclose($fp);
  20.     //get请求
  21.      /*
  22.     $path = $path.'?'.$param;
  23.     $header = "GET $path HTTP/1.0\r\n";
  24.     $header .= 'Host:'.$host."\r\n";
  25.     $header .= 'Connection:Close'."\r\n\r\n";
  26.     fputs($fp, $header);
  27.     fclose($fp);
  28.      */
  29. }
  30. else
  31. {
  32.     echo $error.'__'.$errstr;
  33.    exit;
  34. }
  35. echo 'send ok!';

  36. ?>
复制代码
  1. <?php
  2.     set_time_limit ( 0 );
  3.    ignore_user_abort ( true );

  4.     $i = 0;
  5.    while ( $i ++ < 3 ) {
  6.         file_put_contents($i.'.txt',$_REQUEST['email']);
  7.          sleep ( 3 );
  8.     }
  9.         ?>
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|生活导航|生活导航 ( 新ICP备12003026-1号 )

GMT+8, 2024-4-19 01:21 , Processed in 0.087519 second(s), 14 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表