我們有2臺服務器,dev和live。他們都使用LAMP(Debian),但開發服務器是普通的http,而活動的服務器是https。此代碼的工作完美我們的開發服務器上:file_get_contents + stream_context_create在1臺服務器上工作,在另一臺服務器上阻塞
$all_data = array(...);
$eol = "\r\n";
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($all_data)),
'connection: close'
);
$headers = implode($eol, $headers);
$opts = array(
'http'=>array(
'method' => 'POST',
'header' => $headers,
'content' => json_encode($all_data)
)
);
$context = stream_context_create($opts);
$update_data = file_get_contents($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $system_file, null, $context);
在直播服務器,該的file_get_contents給出了這樣的錯誤:
Warning: file_get_contents(https://...): failed to open stream: Connection timed out in ....php on line 1086
我已經看過了Apache日誌的線索是什麼導致它在現場服務器上失敗,但我只看到上面的錯誤。它沒有說明什麼阻止了這個呼叫。我在活動服務器上將allow_url_include和allow_url_fopen設置爲On。
我不知道它是否在Apache配置或SSL配置中,或其他什麼東西,我不知道在哪裏尋找。我今天花了幾個小時研究這個問題,並嘗試向頭數組(User-Agent,Accept-Language,Accept-Encoding,Cookie等)添加不同的頭文件,但沒有任何工作。我基本上試圖複製開發者的東西,但活着就是不喜歡它。
我也驗證過,如果我直接在瀏覽器中複製並粘貼正在創建的URL,那麼我知道文件名是正確的。
dev server:
php: 5.6.14-0+deb8u1
apache: Apache/2.4.10
debian: 8.2
live server:
php: 5.5.12
apache: Apache/2.4.10
debian: 7.9
連接超時聽起來像是一個防火牆的問題。你是否從實時服務器獲取目的地,或者更好地在端口443上運行nmap? –
嘗試通過服務器上無法運行的'curl'從命令行手動創建https請求。只是:'捲曲https:// ...' – Will
@JeffPuckettII,我試過這個:nmap -p 443 ourdomain.com並得到這個:端口狀態服務 443/tcp過濾https – raphael75