فهرست منبع

Remove "timeout" as a default parameter in Connection\Parameters.

Falling back to a default timeout values should be done by the connection class
as it is an implementation detail that may vary depending on the backend.
Daniele Alessandri 10 سال پیش
والد
کامیت
2b0c8fbb26

+ 4 - 0
CHANGELOG.md

@@ -17,6 +17,10 @@ v1.1.0 (2015-xx-xx)
   These parameters augment the user-supplied parameters when creating a new
   These parameters augment the user-supplied parameters when creating a new
   connection but they do not override specific parameters when already defined.
   connection but they do not override specific parameters when already defined.
 
 
+- Predis\Connection\Parameters does not have a default for "timeout" anymore,
+  falling back to a default value is a responsibility of each connection class.
+  Internally the default timeout for connect() operations is still 5 seconds.
+
 
 
 v1.0.1 (2015-01-02)
 v1.0.1 (2015-01-02)
 ================================================================================
 ================================================================================

+ 0 - 1
src/Connection/Parameters.php

@@ -26,7 +26,6 @@ class Parameters implements ParametersInterface
         'scheme' => 'tcp',
         'scheme' => 'tcp',
         'host' => '127.0.0.1',
         'host' => '127.0.0.1',
         'port' => 6379,
         'port' => 6379,
-        'timeout' => 5.0,
     );
     );
 
 
     /**
     /**

+ 2 - 2
src/Connection/PhpiredisSocketConnection.php

@@ -36,7 +36,7 @@ use Predis\Response\Status as StatusResponse;
  *  - host: hostname or IP address of the server.
  *  - host: hostname or IP address of the server.
  *  - port: TCP port of the server.
  *  - port: TCP port of the server.
  *  - path: path of a UNIX domain socket when scheme is 'unix'.
  *  - path: path of a UNIX domain socket when scheme is 'unix'.
- *  - timeout: timeout to perform the connection.
+ *  - timeout: timeout to perform the connection (default is 5 seconds).
  *  - read_write_timeout: timeout of read / write operations.
  *  - read_write_timeout: timeout of read / write operations.
  *
  *
  * @link http://github.com/nrk/phpiredis
  * @link http://github.com/nrk/phpiredis
@@ -286,7 +286,7 @@ class PhpiredisSocketConnection extends AbstractConnection
         $null = null;
         $null = null;
         $selectable = array($socket);
         $selectable = array($socket);
 
 
-        $timeout = (float) $parameters->timeout;
+        $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0);
         $timeoutSecs = floor($timeout);
         $timeoutSecs = floor($timeout);
         $timeoutUSecs = ($timeout - $timeoutSecs) * 1000000;
         $timeoutUSecs = ($timeout - $timeoutSecs) * 1000000;
 
 

+ 3 - 1
src/Connection/PhpiredisStreamConnection.php

@@ -108,7 +108,9 @@ class PhpiredisStreamConnection extends StreamConnection
     protected function createStreamSocket(ParametersInterface $parameters, $address, $flags, $context = null)
     protected function createStreamSocket(ParametersInterface $parameters, $address, $flags, $context = null)
     {
     {
         $socket = null;
         $socket = null;
-        $resource = @stream_socket_client($address, $errno, $errstr, (float) $parameters->timeout, $flags);
+        $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0);
+
+        $resource = @stream_socket_client($address, $errno, $errstr, $timeout, $flags);
 
 
         if (!$resource) {
         if (!$resource) {
             $this->onConnectionError(trim($errstr), $errno);
             $this->onConnectionError(trim($errstr), $errno);

+ 2 - 2
src/Connection/StreamConnection.php

@@ -23,7 +23,7 @@ use Predis\Response\Status as StatusResponse;
  *  - host: hostname or IP address of the server.
  *  - host: hostname or IP address of the server.
  *  - port: TCP port of the server.
  *  - port: TCP port of the server.
  *  - path: path of a UNIX domain socket when scheme is 'unix'.
  *  - path: path of a UNIX domain socket when scheme is 'unix'.
- *  - timeout: timeout to perform the connection.
+ *  - timeout: timeout to perform the connection (default is 5 seconds).
  *  - read_write_timeout: timeout of read / write operations.
  *  - read_write_timeout: timeout of read / write operations.
  *  - async_connect: performs the connection asynchronously.
  *  - async_connect: performs the connection asynchronously.
  *  - tcp_nodelay: enables or disables Nagle's algorithm for coalescing.
  *  - tcp_nodelay: enables or disables Nagle's algorithm for coalescing.
@@ -94,7 +94,7 @@ class StreamConnection extends AbstractConnection
      */
      */
     protected function createStreamSocket(ParametersInterface $parameters, $address, $flags)
     protected function createStreamSocket(ParametersInterface $parameters, $address, $flags)
     {
     {
-        $timeout = (float) $parameters->timeout;
+        $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0);
 
 
         if (!$resource = @stream_socket_client($address, $errno, $errstr, $timeout, $flags)) {
         if (!$resource = @stream_socket_client($address, $errno, $errstr, $timeout, $flags)) {
             $this->onConnectionError(trim($errstr), $errno);
             $this->onConnectionError(trim($errstr), $errno);

+ 3 - 2
src/Connection/WebdisConnection.php

@@ -33,7 +33,7 @@ use Predis\Response\Status as StatusResponse;
  *  - scheme: must be 'http'.
  *  - scheme: must be 'http'.
  *  - host: hostname or IP address of the server.
  *  - host: hostname or IP address of the server.
  *  - port: TCP port of the server.
  *  - port: TCP port of the server.
- *  - timeout: timeout to perform the connection.
+ *  - timeout: timeout to perform the connection (default is 5 seconds).
  *  - user: username for authentication.
  *  - user: username for authentication.
  *  - pass: password for authentication.
  *  - pass: password for authentication.
  *
  *
@@ -117,10 +117,11 @@ class WebdisConnection implements NodeConnectionInterface
     private function createCurl()
     private function createCurl()
     {
     {
         $parameters = $this->getParameters();
         $parameters = $this->getParameters();
+        $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0) * 1000;
 
 
         $options = array(
         $options = array(
             CURLOPT_FAILONERROR => true,
             CURLOPT_FAILONERROR => true,
-            CURLOPT_CONNECTTIMEOUT_MS => $parameters->timeout * 1000,
+            CURLOPT_CONNECTTIMEOUT_MS => $timeout,
             CURLOPT_URL => "{$parameters->scheme}://{$parameters->host}:{$parameters->port}",
             CURLOPT_URL => "{$parameters->scheme}://{$parameters->host}:{$parameters->port}",
             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
             CURLOPT_POST => true,
             CURLOPT_POST => true,

+ 0 - 2
tests/Predis/Connection/ParametersTest.php

@@ -30,7 +30,6 @@ class ParametersTest extends PredisTestCase
         $this->assertEquals($defaults['scheme'], $parameters->scheme);
         $this->assertEquals($defaults['scheme'], $parameters->scheme);
         $this->assertEquals($defaults['host'], $parameters->host);
         $this->assertEquals($defaults['host'], $parameters->host);
         $this->assertEquals($defaults['port'], $parameters->port);
         $this->assertEquals($defaults['port'], $parameters->port);
-        $this->assertEquals($defaults['timeout'], $parameters->timeout);
     }
     }
 
 
     /**
     /**
@@ -285,7 +284,6 @@ class ParametersTest extends PredisTestCase
             'scheme' => 'tcp',
             'scheme' => 'tcp',
             'host' => '127.0.0.1',
             'host' => '127.0.0.1',
             'port' => 6379,
             'port' => 6379,
-            'timeout' => 5.0,
         );
         );
     }
     }