When I use fsocketopen and fwrite to connect redis in PHP, it returns false sometimes

28 Views Asked by At

my env:php7.3 redis 3.2.8 I tried to troubleshoot this problem based on the number of handles, but there was no result. I no longer know how to troubleshoot this problem. This error is really too frequent. Can anyone help me? Thanks a lot (T_T)

code example:

    public function testRedis(){
        $host = '192.168.86.141'; // Redis host
        $port = 7001; // Redis port
        $redisSocket = fsockopen($host, $port, $errno, $errstr);

        if (!$redisSocket) {
            die("false: $errstr ($errno)\n");
        }

        var_dump(is_resource($redisSocket)); // it print "true"
        $c = var_export(is_resource($redisSocket),true);

        // send command
        $command = "PING\r\n"; //just for test


        $b = fwrite($redisSocket, $command);// some times it returns int,but sometimes it returns false without any other error messgae
        var_dump($b);
     }
        
0

There are 0 best solutions below