Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Michael Fayez's avatar

Allowed memory size of 134217728 bytes exhausted (tried to allocate 41459712 bytes)

Although I made memory Size in php.ini = 256 M

[PHP]
post_max_size = 100M
upload_max_filesize = 100M
variables_order = EGPCS
memory_limit = 256M

[opcache]
opcache.enable_cli=1

it's still getting the error what is the solution ?

0 likes
1 reply
LaryAI's avatar
Level 58

It seems like you've already adjusted your php.ini settings to increase the memory limit, but you're still encountering the memory exhaustion error. Here are a few steps you can take to troubleshoot and resolve this issue:

  1. Confirm the Configuration: Ensure that the changes you've made to your php.ini file are actually being applied. You can do this by creating a PHP file with the following content and navigating to it in your browser:
<?php
phpinfo();

Look for the memory_limit setting to confirm it's set to 256M.

  1. Restart the Server: After making changes to php.ini, you need to restart your web server (e.g., Apache, Nginx) and PHP-FPM (if you're using it) for the changes to take effect.

  2. Check for Local Overrides: Sometimes, the memory limit can be overridden in the application code itself. Look for any ini_set('memory_limit', '...') calls in your PHP scripts that might be setting a lower value.

  3. Increase Memory Limit Temporarily: If you need to temporarily increase the memory limit for a particular script, you can do so with ini_set() at runtime:

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

Place this at the beginning of your script. However, this is not a permanent solution and should be used with caution.

  1. Optimize Your Code: If you're consistently running into memory limit issues, it might be a sign that your code is not optimized and is using more memory than necessary. Look for:

    • Large datasets being loaded into memory all at once. Consider processing data in chunks.
    • Unnecessary duplication of data.
    • Memory leaks, such as circular references or not freeing resources.
  2. Disable Opcache for CLI: If you're running your script through the command line, the opcache.enable_cli=1 setting might be causing issues. Try setting it to 0 to see if that resolves the problem.

  3. Check for Other PHP Configuration Files: PHP can load multiple configuration files. Use php --ini in the command line to see if there are other configuration files being loaded that might override your memory_limit setting.

  4. Profile Your Application: Use a tool like Xdebug to profile your application and find out where the most memory is being used. This can help you identify and fix memory-intensive operations.

If none of these steps resolve the issue, consider providing more context or code examples that might be causing the memory exhaustion. This can help in pinpointing the exact cause and finding a more specific solution.

Please or to participate in this conversation.