Home  >  Article  >  Backend Development  >  phpredis cannot connect to redis remotely?

phpredis cannot connect to redis remotely?

WBOY
WBOYOriginal
2016-12-01 00:56:572018browse

Problem description:

<code>   1、在win8上vmware了一个centos,并且在windows下ping通了centos的ip:192.168.1.101;
   
   2、在windows下安装phpredis,并且在phpinfo中看到了phpredis支持的版本,证明安装成功;
   
   3、在centos下能连上127.0.0.1:6379,正常操作redis存储;
   </code>

Cannot connect under Windows, prompt: Connection timed out. The code is as follows:

<code>       

    <?php
      $redis = new Redis();
      $redis->connect('192.168.1.101', 6379);
      echo "Connection to server sucessfully";
      echo "Server is running: " . $redis->ping();
    ?>
   </code>

Reply content:

Problem description:

<code>   1、在win8上vmware了一个centos,并且在windows下ping通了centos的ip:192.168.1.101;
   
   2、在windows下安装phpredis,并且在phpinfo中看到了phpredis支持的版本,证明安装成功;
   
   3、在centos下能连上127.0.0.1:6379,正常操作redis存储;
   </code>

Cannot connect under Windows, prompt: Connection timed out. The code is as follows:

<code>       

    <?php
      $redis = new Redis();
      $redis->connect('192.168.1.101', 6379);
      echo "Connection to server sucessfully";
      echo "Server is running: " . $redis->ping();
    ?>
   </code>

<code>vim /etc/redis.conf</code>

was modified to

<code>bind 0.0.0.0</code>

Restart the service and check the port

<code>service redis restart
netstat -ntpl |grep redis</code>

You should be able to see listening 0.0.0.0

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn