Title: PHP 7 Memory Limit problems
Last modified: September 1, 2016

---

# PHP 7 Memory Limit problems

 *  [krystoflp](https://wordpress.org/support/users/chrisscottuk/)
 * (@chrisscottuk)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/)
 * My VPS has 2048MB allocated.
 * I have 1024MB allocated in user.ini, and wp-config.php
    If I change user.ini 
   to -1 for unlimited memory the problem still occurs, and also if I allocate 2048MB
   in wp-config.php with define( ‘WP_MAX_MEMORY_LIMIT’, ’1024M’ ); define( ‘WP_MEMORY_LIMIT’,‘
   1024M’ );
 * I get odd error messages in the dashboard. similar to: Fatal error: Allowed memory
   size of 2097152 bytes exhausted (tried to allocate 36864 bytes) in /wp-includes/
   wp-db.php on line 2352
 * If I remove WP_MAX_MEMORY_LIMIT from wp-config.php the problem gets a lot better.
 * I have replicated this on an unconnected test rig, and this seems to only happen
   on PHP 7, so I’m suspecting it’s either a bug in PHP 7, or a problem in wordpress
   itself (I’m not skilled enough to be able to tell)
 * Can anyone else replicate, or offer a solution
 * Thanks,
    Chris

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [emiliskvg](https://wordpress.org/support/users/emiliskvg/)
 * (@emiliskvg)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7602959)
 * I suggest you read [this.](https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP)
   
   And I suggest putting WP_MAX_MEMORY_LIMIT after WP_MEMORY_LIMIT . Makes more 
   sense 🙂
 * > define these variables before wp-settings.php inclusion
 * EDIT: people are suggesting to set the same values in **php.ini** and in **wp_config.
   php**
 *  Thread Starter [krystoflp](https://wordpress.org/support/users/chrisscottuk/)
 * (@chrisscottuk)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7603060)
 * Thank you, I have tried all of that.
    The issue is, if I remove WP_MAX_MEMORY_LIMIT,
   then the available memory increases, but if I include it, it doesn’t matter what
   the value is, it restricts certain admin area functions to nearer 2MB.
 * I include an excerpt from a chat discussion with a tech support person from wodfence:
 * > ” Interestingly, on a test server, if I set WP_MAX_MEMORY_LIMIT to 1024M, 512M,
   > 256M, or even 128M, I get the same error message you do, when viewing certain
   > admin pages, showing up as if the memory limit is only 2 MB!”
 * Currently we’re thinking that it is a bug in PHP 7.0.8, I haven’t tested it with
   PHP 7.09 which has just been released, but this problem doesn’t occur with PHP
   5.
 * What do people think here, could this be a wordpress issue, a PHP issue, or something
   else?
 *  [emiliskvg](https://wordpress.org/support/users/emiliskvg/)
 * (@emiliskvg)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7603069)
 * I’ll try to replicate this bug, anything I should keep in mind?
 *  [emiliskvg](https://wordpress.org/support/users/emiliskvg/)
 * (@emiliskvg)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7603071)
 * _placeholder_
 *  Thread Starter [krystoflp](https://wordpress.org/support/users/chrisscottuk/)
 * (@chrisscottuk)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7603073)
 * Well I’m no expert so I’ve struggled to get an a irate measurement of how much
   memory is available. Phpinfo has been giving incorrect results so I’ve been using
   word fence memory diagnostic.
 * Good luck
 *  [emiliskvg](https://wordpress.org/support/users/emiliskvg/)
 * (@emiliskvg)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7603080)
 * So I tried to set my php.ini to 2048M and 4096M(setting it to ‘-1’ should be 
   infinite, but a few tests showed that ‘-1’ set’s it to 128M).
    “Wordfence Memory
   benchmarking utility version 6.1.12” reported that it coudnt even allocate 50M
   of the 90M test. So maybe that plugin is broken? Setting WP_MEMORY_LIMIT vars
   didnt do anything, only WordPress didnt work if php memory was set to a lower
   number than WP max.
 * I found this simple script online that somewhat measures memory allocation(cant
   guarantee that it’s accurate. On my windows machine with a memory limit of 2048M
   this script could allocate 1.3Gb of memory).
 *     ```
       <pre>
       <?php
       function tryAlloc($megabyte){
           echo "try allocating {$megabyte} megabyte...";
           $dummy = str_repeat("-",1048576*$megabyte);
           echo "pass.";
           echo "Usage: " . memory_get_usage(true)/1048576;
           echo " Peak: " . memory_get_peak_usage(true)/1048576;
           echo "\n";
       }
       for($i=10;$i<4000;$i+=50){
           $limit = $i.'M';
           ini_set('memory_limit', $limit);
           echo "set memory_limit to {$limit}\n";
           echo "memory limit is ". ini_get("memory_limit")."\n";
           tryAlloc($i-10);
       }
       ?>
       </pre>
       ```
   
 *  [Borge](https://wordpress.org/support/users/joeborge0914/)
 * (@joeborge0914)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7603098)
 * Changing core files “they said” is not good. But I guess, this is the only option
   you got to resolve that issue since you’ve got 2GB RAM on your virtual server.
 * Go to wp-includes/default-constants.php
 * change this code
 *     ```
       if ( !defined('WP_MEMORY_LIMIT') ) {
       if ( is_multisite() ) {
       define('WP_MEMORY_LIMIT', '128M');
       } else {
       define('WP_MEMORY_LIMIT', '256M');
       }
       }
   
       if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
       define( 'WP_MAX_MEMORY_LIMIT', '512M' );
       }
       ```
   
 * Let me know if that works for you.
 *  Thread Starter [krystoflp](https://wordpress.org/support/users/chrisscottuk/)
 * (@chrisscottuk)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7603184)
 * Thanks for everyones replies. I found this bug report for wordpress [https://core.trac.wordpress.org/ticket/32075](https://core.trac.wordpress.org/ticket/32075)
   which seems to cover this issue. It has been fixed, and due for release in wordpress
   4.6 on 16th August, so I’m going to hold off any more experimentation until then–
   hoping that it does indeed fix this issue for me (and no doubt others)
 * Thanks

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘PHP 7 Memory Limit problems’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [PHP70](https://wordpress.org/support/topic-tag/php70/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [krystoflp](https://wordpress.org/support/users/chrisscottuk/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/php-7-memory-limit-problems/#post-7603184)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
