Explorar el Código

Added a method to set Connect Timeout. This will help in case user request unknown url where no service is listening.

jaskirat.singh hace 5 años
padre
commit
bc4ca5cf06
Se han modificado 1 ficheros con 12 adiciones y 1 borrados
  1. 12 1
      src/Builder.php

+ 12 - 1
src/Builder.php

@@ -13,7 +13,7 @@ class Builder {
         'RETURNTRANSFER'        => true,
         'FAILONERROR'           => false,
         'FOLLOWLOCATION'        => false,
-        'CONNECTTIMEOUT'        => '',
+        'CONNECTTIMEOUT'        => 30,
         'TIMEOUT'               => 30,
         'USERAGENT'             => '',
         'URL'                   => '',
@@ -62,6 +62,17 @@ class Builder {
         return $this->withCurlOption( 'TIMEOUT_MS', ($timeout * 1000) );
     }
 
+    /**
+     * Set the connect timeout
+     *
+     * @param   float $timeout    The connect timeout for the request (in seconds, fractions of a second are okay. Default: 30 seconds)
+     * @return Builder
+     */
+    public function withConnectTimeout($timeout = 30.0)
+    {
+        return $this->withCurlOption( 'CONNECTTIMEOUT_MS', ($timeout * 1000) );
+    }
+
     /**
      * Add GET or POST data to the request
      *