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
在最后一行,它被写入脚本可能消耗的最大内存量 那么它实际上是什么意思呢?每次脚本执行时,它不会下载超过此数量的内容,或者要执行的脚本所占用的内存(共享类型) 我搜索过但没有得到答案。如果有人能告诉我它的确切含义,以及我如何能够使用 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);
任何想法帮助链接或视图将受到高度赞赏。
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.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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
其中大多数都是不言自明的,但我可以尝试为您总结一下。
max_execution_time
:脚本可以运行的最长时间。如果您要下载 1GB 文件并且脚本始终运行,请将此值从30
提高到300
。max_input_time
:与您的问题无关。memory_limit
:PHP 进程可以消耗的 RAM 量。 RAM 不是磁盘空间,因此只要您的脚本不执行任何内存密集型操作(例如图像处理、数据库操作或将整个 1GB 文件读取到 RAM 中),就可以了。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 from30
to maybe300
.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.memory_limit
是脚本在任何给定时间可以加载到内存的最大数据量。这意味着,如果您尝试将 1GB 文件的全部内容读取到变量中,是的,您会遇到问题。另一方面,如果您将文件直接下载到磁盘(而不是尝试在脚本中读取其内容),则它可以通过内存逐段流式传输,因此您不一定会遇到内存限制。
您还可以使用
fread()
以防止在任何给定时间超过内存限制。
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.