shell - php curl异步请求如何获取结果
迷茫
迷茫 2017-04-11 10:42:52
0
5
571

 function request($url, $payload) {

  $cmd = "curl -X POST -H 'Content-Type: application/json'";
  $cmd.= " -d '" . $payload . "' " . "'" . $url . "'";

  if (!$this->debug()) {
    $cmd .= " > /dev/null 2>&1 &";
  }

  //发送异步请求
  exec($cmd, $output, $exit);
  return $exit == 0;
}
?>
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(5)
伊谢尔伦
$a=exec($cmd, $output, $exit);
迷茫

你用php 的curl函数不行嘛

迷茫

用curl应该不行,不过可以在请求地址调用回调。
用swoole这种网络框架可以

Ty80

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$response = curl_exec($ch);

Peter_Zhu

swoole可以实现异步,你这样做还是同步的

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!