新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

如何解决Nginx下UCenter通讯失败的问题-创新互联

本篇文章给大家分享的是有关如何解决Nginx下UCenter通讯失败的问题,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

创新互联公司自2013年创立以来,是专业互联网技术服务公司,拥有项目成都网站设计、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元香坊做网站,已为上家服务,为香坊各地企业和个人服务,联系电话:18982081108

解决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函数的代码:

functionfsocketopen($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通讯失败的问题,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享名称:如何解决Nginx下UCenter通讯失败的问题-创新互联
分享网址:http://www.wjwzjz.com/article/cdsjhd.html
在线咨询
服务热线
服务热线:028-86922220
TOP