php的执行时间和内存限制

时间:2011-10-13 05:03:34

标签: memory centos execution php

我正在使用centOS 5服务器。当我试图从服务器下载1GB的文件到我的服务器时,我收到了错误

maximum execution time exceeded.

我打开了我的php.ini文件,它写在那里

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

在最后一行写的是Maximum amount of memory a script may consume所以它实际上是什么意思?它不会下载超过每个脚本执行或它的脚本执行的内存(共享类型) 我搜索但没有得到答案。如果有人能告诉我它究竟是什么意思,请问我怎样才能通过PHP从其他服务器下载大约1GB的数据。

修改

我正在使用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);

任何想法帮助链接或视图都将受到高度赞赏。

2 个答案:

答案 0 :(得分:3)

其中大多数都是不言自明的,但我可以试着为你煮沸。

  • max_execution_time:脚本可以运行的最长时间。如果您要下载1GB文件并且脚本一直在运行,请将此值从30增加到300
  • max_input_time:与您的问题无关。
  • memory_limit:PHP进程可以使用的RAM量。 RAM不是磁盘空间,因此只要您的脚本没有执行任何内存密集型操作,如图像处理,数据库操作或将整个1GB文件读入RAM,您就可以了。

答案 1 :(得分:2)

memory_limit是脚本在任何给定时间可以将加载到内存中的最大数据量。这意味着如果您尝试将1GB文件的全部内容读入变量,是的,您将遇到问题。

另一方面,如果您将文件直接下载到磁盘(而不是尝试在脚本中读取其内容),它可以通过内存逐个流式传输,因此您不一定会遇到内存限制

您还可以使用fread()之类的内容手动读取文件块,以防止在任何给定时间超过内存限制。