Browse Source

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

jaskirat.singh 5 năm trước cách đây
mục cha
commit
bc4ca5cf06
1 tập tin đã thay đổi với 12 bổ sung1 xóa
  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
      *