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开发者_JS百科 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 yourphp.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.
- Either increase the
ini_set('memory_limit', '-1');
精彩评论