ZF-8079: Incorrect use of timeout in Zend_Http_Client_Adapter_Curl

Description

When the Curl adapter creates the curl handle it translates the Zend_Http_Client timeout setting into CURLOPT_TIMEOUT. This causes problems when using the adapter for file uploads. The Curl adapter should translate the timeout into CURLOPT_CONNECTTIMEOUT as this is the more compatible setting to how the timeout is used in other adapters.

Here is a patch which fixes the issue:


Index: Http/Client/Adapter/Curl.php
===================================================================
--- Http/Client/Adapter/Curl.php    (revision 549)
+++ Http/Client/Adapter/Curl.php    (working copy)
@@ -78,7 +78,7 @@
         CURLOPT_INFILESIZE,
         CURLOPT_PORT,
         CURLOPT_MAXREDIRS,
-        CURLOPT_TIMEOUT,
+        CURLOPT_CONNECTTIMEOUT,
         CURL_HTTP_VERSION_1_1,
         CURL_HTTP_VERSION_1_0,
     );
@@ -196,7 +196,7 @@
         }
 
         // Set timeout
-        curl_setopt($this->_curl, CURLOPT_TIMEOUT, $this->_config['timeout']);
+        curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);
 
         // Set Max redirects
         curl_setopt($this->_curl, CURLOPT_MAXREDIRS, $this->_config['maxredirects']);

Comments

Hi, Lee. I agree as 2nd change. Because the following method is used in connect() function for setting connection parameters.


curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);

But, It is hard to understand for me to change $_invalidOverwritableCurlOptions definition. Because this array is used in write() function for setting additional curl options in curl execution.

Do you have any idea?

It seems that we do want to prevent people from attempting to change the connect timeout setting as that has already been used. However, the timeout setting might be something people will change after the adapter has been constructed. This will allow people to set a timeout for a specific call and then change it again for another call.

I see, now You can set CURLOPT_CONNECTIONTIMEOUT in the write() instead of the CURLOPT_TIMEOUT if you would want, but it seems to be slightly strange. :-(

So, I will change $_invalidOverwritableCurlOptions so you can set CURLOPT_TIMEOUT in the write().

Solved in r18727(trunk), r18728(1.9 branch)