From 9c14b4bb0779127638a17dd8aab8f05f28c6df43 Mon Sep 17 00:00:00 2001 From: Xon Date: Sat, 18 Mar 2017 23:21:37 +0800 Subject: [PATCH] Handle is an application convert a php error into an Exception --- Client.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Client.php b/Client.php index b3d1a0d..7d4af4a 100755 --- a/Client.php +++ b/Client.php @@ -436,10 +436,20 @@ public function connect() if ( ! $this->redis) { $this->redis = new Redis; } - $socketTimeout = $this->timeout ? $this->timeout : 0.0; - $result = $this->persistent - ? $this->redis->pconnect($this->host, $this->port, $socketTimeout, $this->persistent) - : $this->redis->connect($this->host, $this->port, $socketTimeout); + try + { + $socketTimeout = $this->timeout ? $this->timeout : 0.0; + $result = $this->persistent + ? $this->redis->pconnect($this->host, $this->port, $socketTimeout, $this->persistent) + : $this->redis->connect($this->host, $this->port, $socketTimeout); + } + catch(Exception $e) + { + // Some applications will capture the php error that phpredis can sometimes generate and throw it as an Exception + $result = false; + $errno = 1; + $errstr = $e->getMessage(); + } } // Use recursion for connection retries