Blank page and memory size exhausted - php

I've been working for hours on this issue and I'm about to get mad ! I develop a Symfony 3 application for more than a year, without any big problem. I was implementing some DoctrineEventListeners to my User Entity, everything was fine. But I now have an Error 500 for each page I want to access to (even the ones where there is NO call to these EventListeners). And my php log says this :
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /Applications/MAMP/htdocs/symfonyjf/var/cache/dev/ContainerXu4ttxs/getDoctrine_Orm_DefaultEntityManagerService.php on line 41
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /Applications/MAMP/htdocs/symfonyjf/vendor/symfony/debug/Exception/OutOfMemoryException.php on line 1
I reversed all my last changes, so there is no "new" EventListener in my project. But still, the project still shows a blank page.
Do you have any clue to help me ?
Thanks a lot !

At first you have to clear your cache so you are sure that you are running the correct version of code. Secondly I suggest to use the Symfony Stopwatch Component in order to monitor the memory usage of different code blocks in your project in order to understand where you have the largest memory consumption. Finally, if you can (i.e. you are not using a shared hosting environment) increase PHP allowed memory in your php.ini file.

I finally checked service by service and I found the one that was causing what I guess was an infinite loop. It was an Injection of EntityManager inside a service triggered by a Doctrine EventListener, which is (I guess) not allowed.
Thanks everybody !

Related

Allowed memory size error in Tbs library

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

Laravel 5: PHP Fatal error: Allowed memory size of 33554432 bytes exhausted

I've used laravel 5 for my project and everything was working fine until 2 days before but now I'm stuck with this error
PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 72 bytes) in /home/.../public_html/CMS/vendor/compiled.php on line 9360
I've frontend and backend for this project and my frontend is working all fine without any errors. But when I log in to my backend, I can log in but just get a blank page. I don't find a way to get rid of this error. Please help me Thankyou.
What is your code exactly. Its eating up all the memory. Try optimizing your code. I will not prefer using this but it can be done for a temporary solution.
ini_set("memory_limit",-1);

Concrete5 PHP GD running out of memory

I ran into this rather annoying issue the other day; when a page tries to load it will just 'stop' half way through returning half a page to the end user. The exact error is shown below.
[03-Jul-2015 03:15:04 Europe/London] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 18996 bytes) in [path]/concrete/vendor/imagine/imagine/lib/Imagine/Gd/Image.php on line 602
I spoke to my host and they bumped up PHP's memory to 512M (which is a bit overkill) yet it still throws this error. I'm not sure if it's a memory leak in Concrete5 somewhere or if it is just the server that the site is hosted on.
Any suggestions are much appreciated.
Edit: Forgot to mention I'm running 1.7.4.2
Edit 2: For reference the exact function is imagecreatetruecolor()
Either:
ini_set('memory_limit','256M');
Inside PHP or getting your host to bump up the memory limit will do the trick.

Symfony 2 Allowed memory size vendor/symfony/symfony/src/Symfony/Component/Yaml/Unescaper.php

I move my symfony2 app on the new serwer.
But in my new serwer display only one error (on app.php and app_dev.php) :
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3002456313 bytes) in .../vendor/symfony/symfony/src/Symfony/Component/Yaml/Unescaper.php on line 56
I dont find any problem like this in google.
I try to solve this problem for two days.
Seems to be something about Doctrine (in fact, pretty sure). Are you managing a big set of entities? This means that you are loading a huge collection of entities (maybe a xtomany relation) and you are loading full collection into the memory.
Could you revise if is something about this?

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)

When I login to my web application it shows an error like:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes) in /gt/2.ps.fo/home/hft/domains/console.fo.spalgo.com/public_html/cake/libs/model/datasources/dbo/dbo_mysql.php on line 775
Is there any solution to solve this problem? Why do I get this error?
That sounds like you've allocated more memory than PHP will allow. Edit the memory_limit setting in your site php.ini configuration as described on the linked page.
Another possibility (less likely) is that you've hit the setrlimit(2) resource limits for your user or group. Check /etc/security/limits.conf for limits that might be set for your web server, along with whatever initialization scripts start your server environment and PHP interpreter environment.
The first example I found by searching SO for "PHP out of memory" is this one
Try using echo instead of storing what you are printing to a variable first.
Looking at the file that threw the fatal exception (dbo_mysql.php) I presume that your call is retrieving data from the DataBase.
Also, looking at the memory limit, it shows 134217728 bytes, which is 128MB, so I think that whatever your API call is doing, is trying to fetch a lot of data which total surpasses the limit allocated per script.
For example, if the last script in the API call stack were to use 20MB for its needs and then tires to fetch data from the DB worth 115MB, your script would be trying to allocate 135MB which is already 7MB more than the limit and thus causing the Fatal Exception.
So, I see a few things to check/do:
That you are not retrieving unnecessary data, or in other words, retrieve only what you need.
If you indeed need all that data, then
Either increase the memory_limit value under your php.ini file
Con: If your data keeps growing, you may need to keep updating this value for the only one script and exposing your self to memory leaks or running out of memory.
Or I would recommend that you implement some sort of pagination (which will allow you to keep memory limits in check) and make your application more scalable.
ini_set('memory_limit', '-1');

Categories