我是从Stack Overflow获得此功能的,它确实对我很有帮助,因为它在我的本地系统上可以正常工作,但在我的服务器(Bluehost)上却不起作用。可能是什么问题,或者如何在服务器上对其进行测试以使其正常工作?
function post_async1($url, array $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);
echo $out = "GET ".$parts['path']."?$post_string"." HTTP/1.1\r\n";//you can use POST instead of GET if you like
$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";
fwrite($fp, $out);
fclose($fp);
}
$params['id'] = 36;
post_async1('http://uda:8888/sendmail.php', $params);
答案 0 :(得分:1)
fsockopen函数将用于与端口80(HTTP)或443(HTTPS)上任何URL的出站连接。如果fsockopen尝试使用另一个端口,则在我们将该端口添加到防火墙之前,它将无法工作。您需要要求他们打开插座 bluehost help