PHP fsockopen不适用于本地主机
使用fsockopen()的php函数进行异步请求 当主机为“localhost”或“127.0.0.1”或此服务器的域名时。它不起作用。 如果主机是局域网ip(例如192.168.3.11)地址,则它可以工作 服务器可以从internet上的其他服务器接收fsockopen请求,也可以向internet上的其他服务器发送fsockopen请求 我的代码:PHP fsockopen不适用于本地主机,php,fsockopen,Php,Fsockopen,使用fsockopen()的php函数进行异步请求 当主机为“localhost”或“127.0.0.1”或此服务器的域名时。它不起作用。 如果主机是局域网ip(例如192.168.3.11)地址,则它可以工作 服务器可以从internet上的其他服务器接收fsockopen请求,也可以向internet上的其他服务器发送fsockopen请求 我的代码: function async_post($host,$path,$data){ $post = http_build_query(
function async_post($host,$path,$data){
$post = http_build_query($data);
$len = strlen($post);
$fp = fsockopen( $host , 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";
} else {
$out = "POST $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Content-Length: $len\r\n";
$out .= "\r\n";
$out .= $post."\r\n";
fwrite($fp, $out);
fclose($fp);
}
}
假设问题服务器的域名是:www.problem.com
它的互联网ip地址是:8.8.8.8
它的局域网ip是:192.168.0.123
假设第三方服务器的ip为:9.9.9.9
问题服务器发送请求:
async_post(“127.0.0.1”,“xxx.php”,“$data”)不工作
async_post(“localhost”,“xxx.php”,“$data”)不工作
async_post(“www.problem.com”,“xxx.php”,“$data)不工作
async_post(“9.9.9.9”,“xxx.php”,“$data)工作
第三方服务器发送请求:
async_post(“www.problem.com”,“xxx.php”,“$data)工作您有权访问服务器吗?可能值得检查它是否正在监听所有接口。查看:
netstat-a | grep http
我不知道SRE这样做的原因