mirror of
https://github.com/idanoo/php-resque
synced 2025-07-01 05:32:20 +00:00
Updated Redisent.php to attempt three reconnects to the redis server before giving up. Also supressed fwrite errors.
This commit is contained in:
parent
f6334bb3b8
commit
e4f39a6093
1 changed files with 17 additions and 3 deletions
|
@ -43,6 +43,13 @@ class Redisent {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public $port;
|
public $port;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of times to attempt a reconnect
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $max_reconnects = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Redisent connection to the Redis server on host {@link $host} and port {@link $port}.
|
* Creates a Redisent connection to the Redis server on host {@link $host} and port {@link $port}.
|
||||||
|
@ -73,10 +80,17 @@ class Redisent {
|
||||||
$command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array($this, 'formatArgument'), $args), CRLF), CRLF);
|
$command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array($this, 'formatArgument'), $args), CRLF), CRLF);
|
||||||
|
|
||||||
/* Open a Redis connection and execute the command */
|
/* Open a Redis connection and execute the command */
|
||||||
|
$reconnects = 0;
|
||||||
for ($written = 0; $written < strlen($command); $written += $fwrite) {
|
for ($written = 0; $written < strlen($command); $written += $fwrite) {
|
||||||
$fwrite = fwrite($this->__sock, substr($command, $written));
|
$fwrite = @fwrite($this->__sock, substr($command, $written));
|
||||||
if ($fwrite === FALSE) {
|
if ($fwrite === FALSE || $fwrite === 0) {
|
||||||
throw new Exception('Failed to write entire command to stream');
|
if ($reconnects >= (int)$this->max_reconnects) {
|
||||||
|
throw new Exception('Failed to write entire command to stream');
|
||||||
|
}else{
|
||||||
|
fclose($this->__sock);
|
||||||
|
$this->establishConnection();
|
||||||
|
$reconnects++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue