PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 13374929 bytes) in script.php on line 2
Line 2 is
session_start();.
Sessions are stored in memcached daemon (set via php.ini session.save_path
with default memcached settings (1mb for entry max), meaning session data itself is not supposed to be that big.
Suggestions for debugging?
session.save_handler = memcache
session.save_path="tcp://YOURSERVER:PORT?persistent=1&weight=1&timeout=1&retry_interval=10"
Try to set your php.ini config to something like that...
Session_start itself has no memory overflows.
The error appeared there since this was the straw that broke the camel's back
and nearly the max available memory was allocated already before getting to that line.
Related
I have a strange memory limit issue in PHP. I have to read a lot of data into an array using a particular script, and I keep running out of memory.
My memory is now at 2048M in the php.ini file, and phpinfo() indicates it as such, yet, I keep getting this error:
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 142610432 bytes) in ... on line 173
Now - those two total about 680MB. This is far below the limit I set it to. Why would this error still occur?
Try using ini_set
Sets the value of the given configuration option. The configuration
option will keep this new value during the script's execution, and
will be restored at the script's ending.
ini_set("memory_limit" , "2048M");
In most cases ini_set rewrites all other PHP configurations
i got this error when using php bin/console server:run , and the server won't start.
php bin/console server:run
Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 4096 bytes) in C:\Users\Messkan\Desktop\businessplace\vendor\jms\serializer-bundle\JMSSerializerBundle.php on line 43
Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 32768 bytes) in C:\Users\Messkan\Desktop\businessplace\vendor\symfony\symfony\src\Symfony\Component\Debug\Exception\OutOfMemoryExce
ption.php on line 1
use this command to increase memory allocated:
php -d memory_limit=-1 bin/console server:run
or increase this option in php.ini in your php folder.
You probably have either:
An entity related to thousands of other entities, and by the time you get to a very high amount of records being serialized, memory maxs out, or...
A circular reference in one of your entities
Increasing the memory limit may fix it if is not a circular reference, but that's not a proper fix. You have to be efficient. Control your hydration and references. Also, IMO, JMS Srializer is not the best tool for a presentation layer. Try league/fractal.
You need to increase memory_limit value in php.ini file for the php version you are using (e.g. php7.0).
So navigate to your php.ini file there, find memory_limit line in this file & try to set value to 1G or 2G (depending on the app size, - how much you really need). Save changes & restart your server (apache/nginx), and try once again.
On my localhost, the process in question works fine. It's basically a whole lot of number crunching.
But on my server (CentOS 5.9 + PHP 5 + MySQL 5) it gives me this error:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 80 bytes) in {..}/system/database/drivers/mysql/mysql_result.php on line 147
I'm already declaring the following before running this function:
ini_set('memory_limit', '-1');
The system itself has 8 GB of memory. My local machine has 12 GB of memory. I doubt it needs that much memory, though.
Any insights would be greatly appreciated. Thanks in advance!
PHP has a global memory limit on each system where it runs that overrides your program's own memory_limit setting.
It's the memory_limit value in a file called php.ini. Shared hosting providers often set this to something like 32M. That seems to be your problem. If you control the server you may be able to set it larger.
Otherwise you'll need to rework your program to use less memory. (This is a very common problem when moving from development to production, sad to say.)
Here's some advice on finding that file if you don't know where it is.
Dude, where's my php.ini?
I often saw the php.ini memory_limit but I haven't found the answer to my question.
What EXACTLY is the memory_limit in php.ini?
Please post an detailed example.
Thanks :)
PHP’s memory_limit setting is not a storage space where multiple PHP scripts pool form or grow. The 'memory_limit' directive sets the maximum amount of memory that a PHP script can use. Note that this is dynamically allocated, and not reserved memory. If a script exceeds this value, PHP will report a fatal error.
Fatal error: Allowed memory size of x bytes exhausted (tried to allocate x bytes)
The error means that the allowed memory limit of x bytes configured on your server(memory_limit=xM) was reached while the PHP script tried to allocate y bytes.
It's the limit of the memory of the php script. It avoids than bad code fill the server memory, crashing it.
I'm getting this error:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 3456 bytes) in /home/gigiphot/public_html/Includes/thumbnail.inc.php on line 158
and this PHP memory limit is set to 64mb .. do I increase it? Not sure of next step...
You can set memory_limit in your php.ini file, see here: http://php.net/manual/en/ini.core.php
However, you may want to investigate if you really need such a heavy memory consumption... if this service will be used by multiple users concurrently, you may have problems... An unintended high memory consumption is often a symptom of something going wrong in your script.
Try adding ini_set('memory_limit', '128M'); to the top of the file.
You can set it to -1 to ignore the limit, but it's not generally recommended.