@@ -35,6 +35,13 @@ class ReCaptchaBuilder {
3535 */
3636 protected $ version ;
3737
38+ /**
39+ * The curl timeout
40+ * please visit https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html
41+ * @var int
42+ */
43+ protected $ curl_timeout ;
44+
3845 /**
3946 * Whether is true the ReCAPTCHA is inactive
4047 * @var boolean
@@ -46,11 +53,12 @@ class ReCaptchaBuilder {
4653 */
4754 protected $ api_url = 'https://www.google.com/recaptcha/api/siteverify ' ;
4855
49- public function __construct ($ api_site_key , $ api_secret_key , $ version = 'v2 ' ) {
56+ public function __construct ($ api_site_key , $ api_secret_key , $ version = 'v2 ' , $ curl_timeout = 3 ) {
5057
5158 $ this ->setApiSiteKey ($ api_site_key );
5259 $ this ->setApiSecretKey ($ api_secret_key );
5360 $ this ->setVersion ($ version );
61+ $ this ->setCurlTimeout ($ curl_timeout );
5462 $ this ->setSkipByIp ($ this ->skipByIp ());
5563 }
5664
@@ -78,6 +86,25 @@ public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
7886 return $ this ;
7987 }
8088
89+ /**
90+ * @param int $curl_timeout
91+ * @return ReCaptchaBuilder
92+ */
93+ public function setCurlTimeout (int $ curl_timeout ): ReCaptchaBuilder {
94+
95+ $ this ->curl_timeout = $ curl_timeout ;
96+
97+ return $ this ;
98+ }
99+
100+ /**
101+ * @return int
102+ */
103+ public function getCurlTimeout (): int {
104+
105+ return $ this ->curl_timeout ;
106+ }
107+
81108 /**
82109 * @param string $version
83110 *
@@ -258,7 +285,7 @@ public function validate($response) {
258285 $ curl = curl_init ($ url );
259286 curl_setopt ($ curl , CURLOPT_HEADER , false );
260287 curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
261- curl_setopt ($ curl , CURLOPT_TIMEOUT , 1 );
288+ curl_setopt ($ curl , CURLOPT_TIMEOUT , $ this -> curl_timeout );
262289 curl_setopt ($ curl , CURLOPT_SSL_VERIFYPEER , false );
263290 $ curl_response = curl_exec ($ curl );
264291 }
0 commit comments