In my PHP web application there is this line:
require_once(__DIR__. '/myfiles.phar');
I'm using this to include a self-created PHAR file with ≈8 MB file size.
One customer has a memory_limit setting of 16M.
In this environment, I do receive an error
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16777216 bytes) in /var/www/my.php on line 3
(See also e.g. here)
Since the customer cannot increase the memory_limit setting value, I'm clueless on how to adjust this.
My question:
Is there any way to tell the PHAR functions in PHP to use less memory when "extracting" PHAR files?
(I'm guessing the the size of my PHAR file is directly linked to the memory usage. So the obvious but complicated way would be to reduce the size of the PHAR file).
Related
I have three WooCommerce based shops installed on my server, basically they are identical shops using the same plugins and themes and the assortment is almost identical (product presentation also).
Each store database has less than 100MB.
In one case I have memory problem for PHP scripts, while memory_limit is set to 256M one store still has memory problems. Others work ok.
[01-May-2020 22:23:08 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 14069080 bytes) in /home/shop1/public_html/wp-includes/wp-db.php on line 2951
[01-May-2020 22:33:22 UTC] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 10489856 bytes) in /home/shop1/public_html/wp-includes/functions.php on line 708
I can raise the memory_limit to e.g. 384M and the problem disappears. But why does such a script require more than 256MB and the other two do not? Is it normal?
You might have a memory leak or from what I can understand if you have set 256M and each one is 100MB that means you only have space for 2 of them and hence the 3rd one is running out of ram.
Make sure that on your php.ini you put more ram and then assign enough ram to each webstore that does not surpass your overall amount.
Your php.ini is most likely taking over and setting the overall RAM rather than the ram PER instance. Hope that makes sense.
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.
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.
Hello i am facing the problem of Allowed memory size error. I have created the project in codeigniter, php and I have used Tbs library. Its worked fine but today it display the error:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 258010 bytes) in
/home/abc/public_html/application/libraries/Tbs.php on line
4222
Please give me any suggestions.
If you are using TBS + OpenTBS in order to merge an XLSX file , then there is a known problem fixed with OpenTBS version 1.9.2 : if the number of row to merge is quite numerous, then you can have a very long process or a memory size error when calling $TBS->Show().
Use OpenTBS 1.9.2 or higher which is optimized for this point, and if the process is still long you can optimize more using the OPENTBS_RELATIVE_CELLS command.
"Allowed memory size of XXXXXX bytes exhausted" is a typical error when you don't have, as it's own name says, enough memory available for the php query to run.
Try upgrading memory_limit variable on your php.ini file, or by setting up ini_set('memory_limit', 'XXXM'); on your PHP file that you are running, being XXX the amount of Mb memory that you want to define.
If this isn't the case, you might have a bug in your software that is causing, i.e. a loop that is consuming memory without any control; but as you have said that it did work before...
Anyway, please check all the other answers from StackOverflow on this aspect:
Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)
CodeIgniter Fatal error: Allowed memory size of bytes exhausted
Codeigniter - Allowed memory size exhausted while uploading
Generally this type of occurs when 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.
Never upgrad memory_limit variable on your php.ini file, or by setting up ini_set('memory_limit', 'XXXM'); on your PHP file that you are running, being XXX the amount of Mb memory that you want to define.Letting application to eat memory he wants to is insane step.Try to find out bug does your application wants that much memory?? Find out
I'm getting the following error when trying to run a php script I wrote:
Fatal error: Allowed memory size of
33554432 bytes exhausted (tried to
allocate 56320 bytes) in
/home/evergrf2/public_html/ianburris/p/maptile/mapfetcher.php
on line 43
What confuses me is that it says the allowed memory size is 33554432 bytes and that when the script tried to allocate 56320 bytes of space the allowed memory was exhausted. How is this possible when 56320 is less than 33554432? Maybe I'm misinterpreting what this is saying...
It says that trying to allocate additional 56320 bytes caused memory exhaustion (so it already had at least 33498112 bytes allocated).
allocation of 56320 pushed you above the limit. Increase your limit in php.ini if needed.
to be more clear dont read it as alocating 56320 is more than allowed 33554432. Instead read it as, while allocating 56320, we surpassed the limit of 33554432.
Modified: dont increase without properly debuging and making sure there are no memory leaks.
33554432 bytes is 32MB, which is not huge.
You can increase PHP's memory limit (in php.ini, look for a line that reads 'memory_limit = 32M' and modify it appropriately). I generally use 128M for development and heavy number-crunching.
The other solution is to profile and rewrite your code to use less memory.
I would also profile the script with the help of Xdebug,
to help find possible memory leaks.