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):
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.
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.
I upped the memory limit in my php.ini to 512M and then added the line to index.php as you suggested
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.
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.
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
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
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.