开发者

Sending numerous files via HTTP POST & curl

Problem :

I am having difficulty with reliably sending numerous files via HTTP Post from one web server to another.

I've noticed the success of files being transferred over is dependent on the size and amount of files I choose to send.

What I constitute as a successful transfer is if all files sent from the source server appear in the directory of the receiving server.

//sender script

$ch = curl_init();

$data = array(
    'file1' => '@/var/www/html/uploadtest/largerfile.zip',
    'file2' => '@/var/www/html/uploadtest/largerfile.zip',
    'file3' => '@/var/www/html/uploadtest/smallerfile.zip'
);

curl_setopt($ch, CURLOPT_URL, 'http://domain.com/test/reciever.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$res = curl_exec($ch);

if(curl_exec($ch)){
    print "Error: " . curl_error($ch);
}

echo $res;

//recieving script

print_r($_FILES); //outputs as blank array on failed transfer
move_uploaded_file( $_FILES["file1"]["tmp_name"], "file1.zip" );
move_uploaded_file( $_FILES["file1"]["tmp_nam开发者_如何学运维e"], "file2.zip" );
move_uploaded_file( $_FILES["file1"]["tmp_name"], "file3.zip" );

With the current files being sent across none of them arrive at their destination. If I remove one largerfile.zip then the file transfer is successful.

I am looking for error responses by printing $res but I don't see any despite a failed transfer. *curl_errno* also does not detect anything.

Background :

I've been recommended to use FTP previously but the Web API I'll be using only accepts POST. It's also likely that the files I need to transfer are around 50mbs.

I've also tried changing the following php.ini settings to :

  • post_max_size : 100M
  • upload_max_size : 60M


You wrote:

It's also likely that the files I need to transfer are around 50mbs.

I assume you refer to the filesize on your harddisk per each file.

max_upload_size : 60M (don't you mean upload_max_filesize?!)
post_max_size : 100M

There is a third setting related to file-uploads: memory_limit. That is because those files will be loaded into memory before saved to disk on the server.

You want to transfer three files at once. Every file is about 50 mb. Let's just sum it up:

50 mb + 50 mb + 50 mb = 150 mb

That means:

  • upload_max_filesize (!!) of 60 mb is too low, in case it counts for all three files at once (I can't remember from top of my head if that is the case or not).
  • post_max_size of 100 mb is definitely too low, you will need a higher value here, at least 150m and add a bit more on top. See the manual entry for more info.
  • memory_limit is unknown but it's highly like that it is too low, too.

For testing set memory_limit to 0 (unlimited) and play around with upload_max_filesize and post_max_size to match your needs.

I hope this helps you to solve your issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜