溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何解決Nginx下UCenter通訊失敗的問題

發布時間:2021-10-09 09:53:54 來源:億速云 閱讀:188 作者:柒染 欄目:web開發

本篇文章給大家分享的是有關如何解決Nginx下UCenter通訊失敗的問題,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

解決Nginx下,UCenter通訊失敗的問題。  

現象

最后還是“通信失敗”,不過跟蹤ucenter的代碼,在uc_server/model/misc.php的dfopen()函數中,有如下代碼:

if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) {
     $context = array(
        'http' => array(
           'method' => $post ? 'POST' : 'GET',
           'header' => $header,
           'content' => $post,
           'timeout' => $timeout,
        ),
     );
     $context = stream_context_create($context);
     $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context);

在if條件內設置斷點,即調用fsocketopen()函數失敗的時候,此時查看$errstr變量的內容,其值如下:

Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?

原因

查看fsocketopen函數的代碼:

function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) {
     $fp = '';
     if(function_exists('fsockopen')) {
        $fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
     } elseif(function_exists('pfsockopen')) {
        $fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
     } elseif(function_exists('stream_socket_client')) {
        $fp = @stream_socket_client($hostname.':'.$port, $errno, $errstr, $timeout);
     }
     return $fp;
  }

發現其是調用的fsockopen()函數失敗,在網上查找,發現大多數都是說fsockopen()函數不支持“http://”這樣的host前綴,要直接用網址,類似www.163.com,或者localhost這樣的。

解決

按照網上的說法,我臨時修改代碼如下:

if(!$fp = @fsocketopen('localhost', $port, $errno, $errstr, $timeout)) {
  //if(!$fp   = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme ==   'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) {
     $context = array(
        'http' => array(
           'method' => $post ? 'POST' : 'GET',
           'header' => $header,
           'content' => $post,
           'timeout' => $timeout,
        ),
     );
     $context = stream_context_create($context);
     $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context);
     $fpflag = 1;
  }

暫時直接將第一個參數固定為localhost,重新刷新頁面,終于通信成功:

如何解決Nginx下UCenter通訊失敗的問題                                             

知道了真正原因,將上述的臨時代碼用正確的方式修改就很簡單了,這里就不浪費筆墨了。

以上就是如何解決Nginx下UCenter通訊失敗的問題,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女