替代CURL由于长时间等待 [英] Alternative to CURL due to long waiting
问题描述
Hey Guys我目前运行一个PHP脚本使用CURL将数据发送到另一个服务器,以运行一个PHP脚本,可能需要一分钟的时间运行。
此服务器不返回任何数据。但是CURL请求仍然需要等待它完成,然后它加载其余的orignal页面。我想我的PHP脚本只是发送数据到其他服务器,然后不等待答案。
Hey Guys I currently run a PHP-script using CURL to send data to another server, to do run a PHP-script that could take up to a minute to run. This server doesn't give any data back. But the CURL-request still has to wait for it to complete, and then it loads the rest of the orignal page. I would like my PHP-script to just send the data to the other server and then not wait for an answer.
所以我的问题是我该如何解决这个问题?我读过,CURL总是要等待。您的建议是什么?
So my question is how should I solve this? I have read that CURL always has to wait. What are your suggestions?
谢谢!
推荐答案
作为一个有用的起点,公开地从这里复制
This might be a useful starting point, flagrantly copypasted from here
function curl_post_async($url, $params)
{
foreach ($params as $key => &$val) {
if (is_array($val)) $val = implode(',', $val);
$post_params[] = $key.'='.urlencode($val);
}
$post_string = implode('&', $post_params);
$parts=parse_url($url);
$fp = fsockopen($parts['host'],
isset($parts['port'])?$parts['port']:80,
$errno, $errstr, 30);
//pete_assert(($fp!=0), "Couldn't open a socket to ".$url." (".$errstr.")");(optional)
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($post_string)."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($post_string)) $out.= $post_string;
fwrite($fp, $out);
fclose($fp);
}
这篇关于替代CURL由于长时间等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!