My PHP version is 5.2.9p2. This typical code is what I am using to post a file to another server.
$post_url = "http://www.website.com/upload";
$post_data['file'] = "@$filePath";
$post_data['title'] = "title";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_nm);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_nm);
$return = curl_exec($ch);
I am using a shared server, and its Apache setting says "Timeouts Connection: 180 - Keep-Alive: 3"
If the file size is somewhat big(around 15Mb), any browser shows the timeout message in 3 minutes, and then nothing happens. However, the file is transferred successfully. Just the browser doesn't show its result.
[edit]
As I think, because nothing is loaded before the script finishes, it causes the timeout. I added "curl_setopt($ch, CURLOPT_NOPROGRESS, false );", but it did nothing. I guess it doesn't work at all. I also tried the below code with their file upload API(SOAP).
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
echo $notification_code . $severity . $message . $message_code . $bytes_transferred . $bytes_max;
}
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
$post_data["file"] = file_get_contents("files/$fileName", false, $ctx);
However, it didn't run "stream_notification_callback" function.
Is there any solution to be able to avoid the Apache timeout? I cannot edit Apache setting. Thanks in advance.