I am trying to send big zip files to a tomcat application using curl in a php script. Since it is a big zip file it is going to take some time on the tomcat server to unpack the zip file (about 2-5 minutes), but the curl request never waits more than 30 seconds before it just continue as if it had received an empty response.
Code I can reproduce problem with:
set_time_limit(0);
$uploadURL = 'http://192.168.0.2:8080/some/url/'
$userid = 'a-user';
$password = 'a-password';
$zipfile = '/tmp/myfile.zip';
$ch = curl_init($uploadURL);
curl_setopt($ch, CURLOPT_HEADER, array(
'Connection: Keep-Alive',
'Keep-Alive: 3600'
));
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_USERPWD, $userid.":".$password);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
"uploadMode" => "uploadOnly",
"id" => $id,
"numberOfFiles" => "1",
"file"=>"@".$zipfile.";type=application/zip"
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 45);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
$response = curl_exec($ch);
The only suspect I have left is that curl makes the request and then times out due to a certain number of seconds elapsing without any bytes being sent back or forth (aka between_bytes_timeout). But I cannot find a curl option to help with that, so I am hoping it is something else.
The tomcat server is in the clear, since I can make a request to it with my browser that can lasts hours without problems.
Chances are, that cURL just auto-cancels the request, because of the transfer rate being too low while your Tomcat is unpacking the zip.
This happens if the average transfer rate drops below
CURLOPT_LOW_SPEED_LIMITbytes/second forCURLOPT_LOW_SPEED_TIMEseconds.Try adding the appropriate options with a high time and/or low limit, e.g.:
To quicktest I’d recommend to use a TIME slightly higher than your Tomcat really needs to unpack a given test zip.