开发者

php's execution time and memory limit

开发者 https://www.devze.com 2023-04-12 12:21 出处:网络
I am using centOS 5 server. i got the error while i was attempting to download 1GB of file from server to my server that

I am using centOS 5 server. i got the error while i was attempting to download 1GB of file from server to my server that

maximum execution time exceeded.

i opened my php.开发者_StackOverflow社区ini file, it was written there

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60     ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M      ; Maximum amount of memory a script may consume

in last line it is written Maximum amount of memory a script may consume so what does it mean actually? it will not download more than this per script execution or its about the memory taken by script to be executed (sharing types) i searched but not got the answer of this. Please if any one can tell me what it mean exactly and how can i be able to download approx 1GB of data through script from other server using PHP.

EDIT

code i am using to download the file from server using curl

$username = "user";
$password = "pwd";
$url = "http://domain.com/feeds/";

global $ch;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
$r = time()-(24*60*60); 
$dateit = date("Ymd", $r);
$file8 = "abc".$dateit.".tbz";
$file3 = "abc".$dateit.".tbz.md5";
$file5 = "xyz".$dateit.".tbz";
$file4 = "xyz".$dateit.".tbz.md5";
$file7 = "lmn".$dateit.".tbz";
$file2 = "lmn".$dateit.".tbz.md5";
$file6 = "pqr".$dateit.".tbz";
$file1 = "pqr".$dateit.".tbz.md5";
$arr = array($file1, $file2, $file3, $file4, $file5, $file6);
for($i=0;$i<=4;$i++)
{

 $url = "http://domain.com/feeds/current-data/".$arr[$i];
 curl_setopt($ch, CURLOPT_URL, $url);

 $fp = fopen("adminArea/folder1/".$arr[$i], 'w+');
 curl_setopt($ch, CURLOPT_FILE, $fp);
 curl_exec ($ch);

}
fclose($fp);
curl_close($ch);

Any idea help link or view will be highly appreciated.


Most of them are self-explanatory, but I can try to boil them down for you.

  • max_execution_time: The maximum time the script can run. If you are downloading a 1GB file and the script is running the whole time, bump this value up from 30 to maybe 300.
  • max_input_time: Not relevant to your problem.
  • memory_limit: The amount of RAM that a PHP process can consume. RAM isn't disk space, so as long as your script isn't doing anything memory-intensive like image processing, database operations, or reading your whole 1GB file into RAM, you're fine.


The memory_limit is the max amount of data the script can have loaded into memory at any given time. That means that if you try and read the entire contents of a 1GB file into a variable, yes, you'll run into problems.

On the other hand, if you download the file directly to disk (rather than trying to read its contents in your script), it can be streamed through memory piece by piece, and thus you wouldn't necessarily run into memory limitations.

You could also manually read the file chunk by chunk using things like fread() to keep from going over the memory limit at any given time.

0

精彩评论

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

关注公众号