phpredis cannot connect to redis remotely?

WBOY
Release: 2023-03-02 07:54:02
Original
2028 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

<code>vim /etc/redis.conf</code>
Copy after login

was modified to

<code>bind 0.0.0.0</code>
Copy after login

Restart the service and check the port

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

You should be able to see listening 0.0.0.0

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!