Mysterious "Fatal error: Allowed memory size exhausted in Unknown on line 0"

Hello all,

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.

aku pernah kayak gini bro…di project lama ku…

situ pake webserver di linux apa windows bro…?

kalo itu sih applikasinya terlalu berat sampe memory server ga kuat.

coba di config web servernya gedein mem_cache=256M (kalo ga salah sih ini kalo di apache linuxku)

pokoknya gedein alokasi memory buat kerja server…

atau bisa juga di atur maxrequestperchild nya\

baca deh

rupanya di php.ini bro… memory_limit

ah. Terima kasih atas sarannya bro :D

karena ini forum internasional jadi saya balas bahasa Inggris saja ya~

It is Linux webserver. How could I know the application is too heavy?

Because I even try to access at the simplest controller action and it still show the error.

Maybe I shall try your suggestion to configure mem_cache, but because this is share-hosting, I want to make sure first…

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:


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:


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 :(

Try increase the allow memory usage for php in php.ini for your web server. May be try 32MB, 64MB, 96MB, and so on.

same with me…

as i say to you in first reply…

‘exhausted’ refer to your memory size.

try to bigger your memory @php.ini


you can try to 32M or bigger

according to memory_get_limit() it already 180M, but it is share hosting. Are they correlate?

maybe you can try ini set


or maybe because of shorttag ‘<?’ php

I’m experiencing the same issue. Unfortunately haven’t run across any solutions yet

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.