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:19
ini_set('memory_limit', '-1');
查看更多
还给你的自由
3楼-- · 2018-12-31 04:25

Write

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

in your index.php at the top after opening of php tag

查看更多
有味是清欢
4楼-- · 2018-12-31 04:25

I notice many answers just try to increase the amount of memory given to a script which has its place but more often than not it means that something is being too liberal with memory due to an unforseen amount of volume or size. Obviously if your not the author of a script your at the mercy of the author unless your feeling ambitious :) The PHP docs even say memory issues are due to "poorly written scripts"

It should be mentioned that ini_set('memory_limit', '-1'); (no limit) can cause server instability as 0 bytes free = bad things. Instead, find a reasonable balance by what your script is trying to do and the amount of available memory on a machine.

A better approach: If you are the author of the script (or ambitious) you can debug such memory issues with xdebug. The latest version (2.6.0 - released 2018-01-29) brought back memory profiling that shows you what function calls are consuming large amounts of memory. It exposes issues in the script that are otherwise hard to find. Usually, the inefficiencies are in a loop that isn't expecting the volume it's receiving, but each case will be left as an exercise to the reader :)

The xdebug documentation is helpful, but it boils down to 3 steps:

  1. Install It - Available through apt-get and yum etc
  2. Configure it - xdebug.ini: xdebug.profiler_enable = 1, xdebug.profiler_output_dir = /where/ever/
  3. View the profiles in a tool like QCacheGrind, KCacheGrind
查看更多
倾城一夜雪
5楼-- · 2018-12-31 04:27

If you are trying to read a file, that will take up memory in PHP. For instance, if you are trying to open up and read an MP3 file ( like, say, $data = file("http://mydomain.com/path/sample.mp3" ) it is going to pull it all into memory.

As Nelson suggests, you can work to increase your maximum memory limit if you actually need to be using this much memory.

查看更多
余生请多指教
6楼-- · 2018-12-31 04:27

I had the same issue which running php in command line. Recently, I had changes the php.ini file and did a mistake while changing the php.ini

This is for php7.0

path to php.ini where I made mistake: /etc/php/7.0/cli/php.ini

I had set memory_limit = 256 (which means 256 bytes)
instead of memory_limit = 256M (which means 256 Mega bytes).

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M

Once I corrected it, my process started running fine.

查看更多
临风纵饮
7楼-- · 2018-12-31 04:28

You can increase the memory allowed to php script by executing the following line above all the codes in the script:

ini_set('memory_limit','-1'); // enabled the full memory available.

And also de allocate the unwanted variables in the script.

Check this php library : Freeing memory with PHP

查看更多
登录 后发表回答