作者:叶蕊2502860197 | 来源:互联网 | 2023-07-30 19:11
shell-phpcurl异步请求如何获取结果:functionrequest($url,$payload){$cmdcurl-XPOST-HContent-Type:applic
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;
}
?>
回复内容:
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;
}
?>
$a=exec($cmd, $output, $exit);
你用php 的curl函数不行嘛
用curl应该不行,不过可以在请求地址调用回调。
用swoole这种网络框架可以
$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);
swoole可以实现异步,你这样做还是同步的