I have problem on my online site. Sometimes the web will show error message “Fatal error: Allowed memory size of xxxxxxx bytes exhausted (tried to allocate yyyyyyyy bytes) in Unknown on line 0”. Following is some strangeness that I haven’t figure out what is the cause of this:
This error line is not in Yii usual error format, but in plain PHP error message (I don’t turn off the debug mode and other error is still in Yii’s format).
It not always occurred, but randomly. About 70% the error will show up.
The error only happened to one Yii application. My website have some other web applications, some are Yii, others wordpress. None of these have the problem. It only happened to one application.
It happened to all of my Yii-based web. I never touch my Yii Framework, but today all of my Yii-base application now has this problem.
It even error in the very simple script, SiteController only render an view file index.php file which only content some echoes.
The very same application run smoothly on my localhost
I’ve tried to memory_get_usage() at the most of part of the script and at the very end of the script, none of indication it exceed the limitation
I tried to die() at the end of controller’s action, it show the error.
I tried to die() at the very first of controller’s action, it sometimes show “X-Powered-By: PHP/5.2.15” instead of the fatal error message
I purposely made Yii throw exception (render non-exist file), the fatal error message still come out, but not in Yii error message, it render at the bottom of the page in plain php format instead.
After tracing down the script, I’ve found out the code that causes memory limit exceeded. It is set_include_path().
Yii’s import() method use set_include_path() when it is dealing xxxx.yyyy.* format. Later, I created a file which only consist of one line:
set_include_path('/usr/lib/php');
and it produce a lot of strange characters and symbols, and pieces of my codes. This output when I save it, size about 16MB. And if I append echo below the code:
set_include_path('/usr/lib/php');
echo "x";
it will produce “x” instead of the strange characters. But it also produce “Fatal error: memory limit …”. I think this topic is not related to Yii’s Framework anymore. But if you have any experiences or knowledge about this problem, maybe can give me some suggestions or ideas. Because I’m really clueless now. Never found such a strange problem
Yii logger leaks memory. My console application was performing a loop of a couple of millions AR requests. Logger was consuming all my memory. Disabling it solved the issue.