我在两个docker站点site1.example.com和api.example.com上遇到问题。这两个站点都通过docker托管在我的本地计算机上。我试图通过curl向api.example.com发出请求,如下所示:
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://api.example.com');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,1000);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_HEADER, 1);
curl_setopt($curl_handler, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl_handle, CURLOPT_PROXY, true);
curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($curl_handle);
if($result === false) {
$error = curl_error($curl_handle);
print_r($error);
}
print_r($result);
curl_close($curl_handle);
发生了什么事
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* Rebuilt URL to: http://api.example.local/?is_deleted=0"
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* Trying 0.0.0.1..."
172.xx.x.x - 27/Nov/2018:18:23:03 +0000 "GET /index.php" 200
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* TCP_NODELAY set"
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* Immediate connect fail for 0.0.0.1: Invalid argument"
[27-Nov-2018 18:23:04] WARNING: [pool www] child 352 said into stderr: "* Closing connection 0"
但是相同的代码可以在生产环境中正常工作。我在php:7.2-fpm上,知道使用docker的curl有什么问题吗?