Php 使用fsockopen,如何在不等待API返回的情况下异步调用API?
我使用此代码段异步调用API:Php 使用fsockopen,如何在不等待API返回的情况下异步调用API?,php,asynchronous,curl,fsockopen,Php,Asynchronous,Curl,Fsockopen,我使用此代码段异步调用API: 公共函数postUrlAsync($url) { $post_字符串=“”; $parts=parse_url($url); 如果(!empty($parts['query'])){ $queryParams='?。$parts['query']; } $fp=fsockopen($parts['host'],isset($parts['port'])?$parts['port']:80,$errno,$errstr,90); 如果($fp
公共函数postUrlAsync($url)
{
$post_字符串=“”;
$parts=parse_url($url);
如果(!empty($parts['query'])){
$queryParams='?。$parts['query'];
}
$fp=fsockopen($parts['host'],isset($parts['port'])?$parts['port']:80,$errno,$errstr,90);
如果($fp){
$out=“POST”。$parts['path'].$queryParams。“HTTP/1.1\r\n”;
$out.=“主机:”.$parts[“主机”]。“\r\n”;
$out.=“内容类型:应用程序/x-www-form-urlencoded\r\n”;
$out.=“内容长度:”.strlen($post\u字符串)。“\r\n”;
$out.=“Referer:”.$this->app\u config['checkout\u processor\u url']。“\r\n”;
$out.=“连接:关闭\r\n\r\n”;
$result=fwrite($fp,$out);
fclose($fp);
返回$result;
}
}
}