php 已用完 134217728 字节的允许内存大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12264253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:10:24  来源:igfitidea点击:

Allowed memory size of 134217728 bytes exhausted

phpmemorymemory-management

提问by You Kuper

Hot to solve this problem and why it happens?

热解决这个问题,为什么会发生?

Zend Server Log:

Zend 服务器日志:

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 538798977 bytes) in C:\Program Files (x86)\Zend\Apache2\htdocs\test\modules\main.php on line 3

PHP 致命错误:第 3 行 C:\Program Files (x86)\Zend\Apache2\htdocs\test\modules\main.php 中允许的内存大小为 134217728 字节(试图分配 538798977 字节)

The file main.phpdoes not produce any error, if it's executed directly from browser. However, if I use its functions from another PHO file, then Zend Log prints the above-mentioned error.

main.php如果直接从浏览器执行该文件,则不会产生任何错误。但是,如果我从另一个 PHO 文件中使用它的函数,则 Zend Log 会打印出上述错误。

回答by shail

I have also encounted this problem.

我也遇到过这个问题。

Increase the following variables so that your page execution will not stop:

增加以下变量,以便您的页面执行不会停止:

  • max_input_time
  • memory_limit
  • max_execution_time
  • max_input_time
  • memory_limit
  • max_execution_time

回答by slugonamission

Either increase the memory limit in php.ini, or try to optimise any large data structures (like arrays) out of your application.

要么增加 中的内存限制php.ini,要么尝试优化应用程序中的任何大型数据结构(如数组)。

In any case, if your PHP application is using 128MB of RAM, something is probably going wrong.

在任何情况下,如果您的 PHP 应用程序使用 128MB 的 RAM,那么可能会出现问题。

Also, as noted by Fluffeh in the comments, what on earth are you doing to utilise 500MB of RAM?

另外,正如 Fluffeh 在评论中所指出的,你到底在做什么来利用 500MB 的 RAM?

回答by slugonamission

Try this:

尝试这个:

ini_set('memory_limit', '-1');

php.net/memory_limit

php.net/memory_limit

It will take unlimited memory usage of server.

它将占用服务器的无限内存使用量。

回答by RafaSashi

In addition to user1427811 you can monitor time_limitand memory_limitbefore and after downloading the file:

除了可以监视user1427811time_limitmemory_limit之前和下载文件后:

function custom_put_contents($source_url='',$local_path=''){

    $time_limit = ini_get('max_execution_time');
    $memory_limit = ini_get('memory_limit');

    set_time_limit(0);
    ini_set('memory_limit', '-1');      

    $remote_contents=file_get_contents($source_url);
    $response=file_put_contents($local_path, $remote_contents);

    set_time_limit($time_limit);
    ini_set('memory_limit', $memory_limit); 

    return $response;
}