Yii Framework Forum: PHP Fatal error: Allowed memory size exhausted - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

PHP Fatal error: Allowed memory size exhausted Memory error when loading framework Rate Topic: ****- 1 Votes

#1 User is offline   littlewyvern 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 01-March 11

Posted 25 August 2011 - 03:41 AM

Hello. I have been running into a problem, and after getting absolutely nowhere on my own I am desperately hoping that someone here can point me in the right direction.

I am running a Yii-based site ( version 1.1.8 ) on a CentOs server (5.6 x86_64). It is running Apache 2.2 with PHP 5.3.8 and MySQL 5.1.56

The problem is this: with every single page request that goes through Yii my server spits out the following (both onto the html page and into the error log):

Quote

PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 353413232 bytes) in Unknown on line 0


I have increased the maximum allowed memory in my php file over and over again, but no matter how high I set the limit (went up to 512MB), the same error occurs (although the particular numbers obviously increase).

When I load a non-yii php page (simple php test files) I have no issues at all. When I run the same yii-site code on my local machine I have no issues at all. I installed a new, blank yii site onto the server (the default testdrive sample site) and that too gives me the memory error. When I turn on the debugger I see no problems with any of the page requests, memory usage is all normal. The problem appears to be happening before any of my own code is loaded, at some point during the yii framework bootstrap load. The fact that the error says "Unknown on line 0" doesn't help to point me in any direction whatsoever.

The server is running APC and memcached - and I thought that might be the problem - but even when I remove them from my php.ini I still get the errors. It makes no difference whether I use yii.php or yiilite.php in my index file. The debugging lines in the index file are also commented out.

Does anyone have any suggestions as to what might be happening here? Any suggestions as to how I might even approach solving this problem?

Anyone who can help will immediately become my new best friend.

Thanks,
Jason
0

#2 User is offline   Maurizio Domba 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,228
  • Joined: 12-October 09
  • Location:Croatia

Posted 25 August 2011 - 03:52 AM

Have you checked the Yii requirements on the server?

http://www.yiiframew...on#requirements
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   littlewyvern 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 01-March 11

Posted 25 August 2011 - 03:55 AM

View Postmdomba, on 25 August 2011 - 03:52 AM, said:

Have you checked the Yii requirements on the server?

http://www.yiiframew...on#requirements


Yep. All are passed and in green except for three warnings in yellow:

PDO PostgreSQL extension
SOAP extension
GD extension
0

#4 User is offline   Maurizio Domba 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,228
  • Joined: 12-October 09
  • Location:Croatia

Posted 25 August 2011 - 03:59 AM

Really strange... when you say "testdrive sample site" you mean the default code generated by yiic ?

Edit:

some ideas to check:

- check the phpinfo() to se the value of memory_limit (could be that there are more php.ini files)
- try to set memory_limit from index.php with
ini_set("memory_limit","128M");

Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   lubosdz 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 108
  • Joined: 25-July 10
  • Location:Slovakia, Bratislava

Posted 25 August 2011 - 04:09 AM

This looks like misconfiguration, possibly .htaccess or hosting memory issue.

check out:

http://www.yiiframew...nown-on-line-0/

http://www.magentoco...ewthread/38843/

Eventually put up here your .htaccess content...

Lubos
Yii extension: Captcha Extended

Greatest discoveries in 22nd century will be about the gravitation. | Homepage: http://www.synet.sk
0

#6 User is offline   littlewyvern 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 01-March 11

Posted 25 August 2011 - 04:37 AM

Sorry, when I say "testdrive site" I mean the base sample site generated by running yiic. I worried that perhaps it was an issue with the relations in my own models so I wanted to try a site with no attached database and no customized models.

My php.ini memory limit is listing the limit correctly.

The only solutions that I have seen suggested elsewhere are to increase the maximum memory size. What strikes me as odd is that whenever I increase the memory size, it merely raises the ceiling level that is ultimately crashed into anyways. If I set the limit to 200, the error says 200MB limit exceeded. If I raise the limit to 500, the error says 500MB limit exceeded. It seems like no matter how high I set the limit it will always be reached. Having a php memory limit of 256MB (as it's set now, and as is shown in the error message from my op) strikes me as being excessively high anyways. Other threads suggest raising the limit to 56M or 96M, and I have more than doubled that already.

The server is a dedicated webserver being hosted by inmotionhosting. According to the linked thread it seems that inmotion in particular has problems. I will try following the advice in that thread and see what happens.

Thanks for the help.
0

#7 User is offline   littlewyvern 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 01-March 11

Posted 25 August 2011 - 04:49 AM

hmmmm... the errors seem to have stopped.

I upped the memory limit in my php.ini to 512M and then added the line to index.php as you suggested

ini_set("memory_limit","512M");


That appears to have done the trick. Hopefully it stays that way.

As a curiosity, isn't 512M a ton of memory to allocate to a single PHP script? I thought yii in particular was meant to be very lightweight, but reserving half a gig per script strikes me as extremely non-lightweight.

Thanks for all of your help though! It's great to have some new best friends.
0

#8 User is offline   Maurizio Domba 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,228
  • Joined: 12-October 09
  • Location:Croatia

Posted 25 August 2011 - 04:57 AM

Yii does not need so much memory... should be something with the server configuration, but difficult to say what without investigating...
Find more about me.... btw. Do you know your WAN IP?
0

#9 User is offline   littlewyvern 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 01-March 11

Posted 25 August 2011 - 08:56 PM

After 24 hours with the above changes the error log contains five new memory error entries. That's a big improvement over having an error on every request, but obviously still not great.

If it is in fact a server configuration problem like you're guessing, do you have any suggestions on how I might go about figuring out the config problem? Any particular tools I could try or tips on places that I could look? This may be a bit beyond the scope of a Yii Bug, but I am still very new when it comes to server setups... particularly on a linux system.

Thanks.
0

#10 User is offline   Maurizio Domba 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,228
  • Joined: 12-October 09
  • Location:Croatia

Posted 26 August 2011 - 01:39 AM

Not really sure... you would need to profile the script to try to find where the memory is taken...

To begin try with Yii performance profiling - http://www.yiiframew...mance-profiling
Find more about me.... btw. Do you know your WAN IP?
0

#11 User is offline   Frank Segelke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 22-November 11

Posted 22 November 2011 - 03:53 PM

Hello Yii-Fans,
I've had the same problem.

My Solution: I set the configuration-value of "display errors" in the "php.ini" to "on". And now, my problems went away.

For Server-Admins with Plesk-Administration:
Create a file "vhost.conf" in the "conf"-Directory of domain.
Edit the file and add following lines:

#
php_value memory_limit 128M
php_admin_flag display_errors on
#

Then save the file and return to the shell-prompt.
Execute the command: /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain

Now: Feel again the wonderful Magic of this Framework. ;-}
0

#12 User is offline   keiooz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 29-December 11

Posted 31 January 2012 - 12:13 AM

Long time back I also having the same problem,but I contacted the In Motion technical support team and solved my problem
0

#13 User is offline   Mike Chojnacki 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 31-January 12

Posted 01 February 2012 - 06:44 AM

Memory limit errors in PHP are tricky to troubleshoot, remember that the OS and service(apache) may impose their own limits on PHP - like someone said earlier, try to set the memory limit in apache if the error returns, and for future reference :)
0

#14 User is offline   neopersia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-January 12

Posted 28 April 2012 - 05:30 PM

I'm experiencing the same problem here on my development system (windows 7, zend server 5.6, php 5.3 and memory_limit 128M)
I think something is wrong with the Yii framework (probably Menu widget?) because I've never had this error before using Yii

has anybody figured out how to fix this error without extending the memory limit?
0

#15 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 2,640
  • Joined: 17-January 09
  • Location:Russia

Posted 29 April 2012 - 05:10 PM

128M is a ton of memory for Yii. Typical website uses no more than 8—9 MB per page run. Can be a bit more if AR is used heavily. CMenu was used in production projects by many-many people so there shouldn't be any issue with it.

Either you have some server misconfiguration or using AR without limit with huge amount of data.
0

#16 User is offline   neopersia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-January 12

Posted 30 April 2012 - 07:06 AM

View Postsamdark, on 29 April 2012 - 05:10 PM, said:

128M is a ton of memory for Yii. Typical website uses no more than 8—9 MB per page run. Can be a bit more if AR is used heavily. CMenu was used in production projects by many-many people so there shouldn't be any issue with it.

Either you have some server misconfiguration or using AR without limit with huge amount of data.


exactly, 128M is a lot of memory for a single user development machine. that's actually what makes me nervous using Yii in a production server!

I don't use ARs at all. last time I had this error was on a simple page with a static view (just printing an html form) and a couple of CMenu widgets. passing different values to the CMenu widgets raised some memory errors
the confusing part is that the error is not always persistent and reloading the webpage sometimes makes the error go away!

I think if this was a server misconfiguration I would have the error in my other projects too. I'm not much of a server admin though so if there's any (mis)configuration capable of raising this error I would appreciate it if you point me into the right direction :)
0

#17 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 2,640
  • Joined: 17-January 09
  • Location:Russia

Posted 02 May 2012 - 06:02 AM

Can you create a simple application that produces this error in your environment so you'll send it to us and we'll be able to try reproducing it?
0

#18 User is offline   saegeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 244
  • Joined: 09-December 09
  • Location:Montpellier - France

Posted 03 May 2012 - 07:27 AM

Or you are surely editing the wrong PHP.INI file
Sometimes there are 2 ini files:
  • /etc/php5/apache2/php.ini
  • /etc/php5/cli/php.ini

And [for] their saying, "Indeed, we have killed the Messiah, Jesus, the son of Mary, the messenger of God ." And they did not kill him, nor did they crucify him; but [another] was made to resemble him to them. And indeed, those who differ over it are in doubt about it. They have no knowledge of it except the following of assumption. And they did not kill him, for certain.Rather, God raised him to Himself.
0

#19 User is offline   Rangel Reale 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-January 10

Posted 03 May 2012 - 08:21 AM

I am just in the process of memory optimization in my very large application (each request can return more than 40mb of XML), and I can say that for a normal Yii application, each request should not use more than 15MB.

My application was using 100MB per request, now optmized it uses ~25MB.

These things helped immenselly:

- Removing ioncube from Yii, and using APC: ioncube doubles the memory usage, and APC doesn't work with it. APC alone on Yii lowered the memory about 30%;
- Don't use AR when too many record, like exporting XML. Making the queries by hand, the performance increased more that 30%, and memory usage lowered by 20%;
- Use a newer PHP version. Old PHP versions have many memory leaks.

I did a large study of Yii memory usage, I can say for sure that the problem isn't with Yii.
0

#20 User is offline   neopersia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-January 12

Posted 04 May 2012 - 11:51 PM

View Postsamdark, on 02 May 2012 - 06:02 AM, said:

Can you create a simple application that produces this error in your environment so you'll send it to us and we'll be able to try reproducing it?


I haven't been able to reproduce this error so far. all I get is random fatal errors which will be gone by refreshing the page!

this is the latest error message I got, trying to write a new module:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 541975884 bytes) in D:\WebServer\hosts\localhost\yii-1.1.10.r3566\framework\YiiBase.php on line 418


as you can see the script tries to allocate more than 516 MB while the memory limit is 128MB
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users