Allowed memory size of 33554432 bytes exhausted (t

2018-12-31 04:08发布

This error message is being presented, any suggestions?

Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php

19条回答
唯独是你
2楼-- · 2018-12-31 04:29

Switching the server to php 7.x solved the issue in my case

查看更多
倾城一夜雪
3楼-- · 2018-12-31 04:30

At last I found the answer:

Just add this below line to before line of you getting error in your file

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

It will take unlimited memory usage of server, it's working fine.

Thanks for giving suggestion friends.

查看更多
忆尘夕之涩
4楼-- · 2018-12-31 04:30

wordpress users add line:

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

in wp-settings.php which you can find in the wordpress installed root folder

查看更多
春风洒进眼中
5楼-- · 2018-12-31 04:30

I hadn't renewed my hosting and the database was read-only. Joomla needed to write the session and couldn't do it.

查看更多
只靠听说
6楼-- · 2018-12-31 04:34

Your script is using too much memory. This can often happen in PHP if you have a loop that has run out of control and you are creating objects or adding to arrays on each pass of the loop.

Check for infinite loops.

If that isn't the problem, try and help out PHP by destroying objects that you are finished with by setting them to null. eg. $OldVar = null;

Check the code where the error actually happens as well. Would you expect that line to be allocating a massive amount of memory? If not, try and figure out what has gone wrong...

查看更多
柔情千种
7楼-- · 2018-12-31 04:35

Doing :

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

is never good. If you want to read a very large file, it is a best practise to copy it bit by bit. Try the following code for best practise.

$path = 'path_to_file_.txt';

$file = fopen($path, 'r');
$len = 1024; // 1MB is reasonable for me. You can choose anything though, but do not make it too big
$output = fread( $file, $len );

while (!feof($file)) {
    $output .= fread( $file, $len );
}

fclose($file);

echo 'Output is: ' . $output;
查看更多
登录 后发表回答