Search code examples
phpmemorymemory-managementout-of-memorymemory-limit

Allowed memory size of X bytes exhausted


Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 13965430 bytes)

PHPInfo shows that I have a memory_limit of 128M, so I'm confused as to why the error says I only have 64M. Is it possible for phpinfo to report incorrectly? Or for PHP to use two separate php.inis?

The error was being caused by an ini_set call in one of the primary php files that a co-worker of mine added without my knowledge.


Solution

  • PHP's config can be set in multiple places:

    1. master system php.ini (usually in /etc somewhere)
    2. somewhere in Apache's configuration (httpd.conf or a per-site .conf file, via php_value)
    3. CLI & CGI can have a different php.ini (use the command php -i | grep memory_limit to check the CLI conf)
    4. local .htaccess files (also php_value)
    5. in-script (via ini_set())

    In PHPinfo's output, the "Master" value is the compiled-in default value, and the "Local" value is what's actually in effect. It can be either unchanged from the default, or overridden in any of the above locations.

    Also note that PHP generally has different .ini files for command-line and webserver-based operation. Checking phpinfo() from the command line will report different values than if you'd run it in a web-based script.