上一篇文章《Nginx下,請求本機另外Host很慢》中,到最後仍是「通訊失敗」,不過跟蹤ucenter的代碼,在uc_server/model/misc.php的dfopen()函數中,有以下代碼:php
if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { |
在if條件內設置斷點,即調用fsocketopen()函數失敗的時候,此時查看$errstr變量的內容,其值以下:ide
Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?函數
查看fsocketopen函數的代碼:post
function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) { |
發現其是調用的fsockopen()函數失敗,在網上查找,發現大多數都是說fsockopen()函數不支持「http://」這樣的host前綴,要直接用網址,相似www.163.com,或者localhost這樣的。orm
按照網上的說法,我臨時修改代碼以下:server
if(!$fp = @fsocketopen('localhost', $port, $errno, $errstr, $timeout)) { |
暫時直接將第一個參數固定爲localhost,從新刷新頁面,終於通訊成功:ip
知道了真正緣由,將上述的臨時代碼用正確的方式修改就很簡單了,這裏就不浪費筆墨了。