3

I'm running a small Wordpress blog for my sister on a very common CentOS 5.11 with Apache 2 and PHP 5.3.3.

Lately, we discovered while she tried to update or install anything using Wordpress own interface it all stalled, and I found this:

PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 20 bytes) in /var/www/foobar/wp-admin/includes/file.php on line 159, referer: http://foobar.com/wp-admin/update-core.php?action=do-core-upgrade

After searching for a bit the easiest thing seemed to be to just raise the memory limit a bit, but irregardless of how much I raise it to it basically just takes longer for it to hit this roof.

Here's some excerpts:

512M

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 261900 bytes) in /var/www/foobar/wp-admin/includes/file.php on line 159, referer: http://foobar.com/wp-admin/update-core.php?action=do-core-upgrade

1024M

PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 261900 bytes) in /var/www/foobar/wp-admin/includes/file.php on line 159, referer: http://foobar.com/wp-admin/update-core.php?action=do-core-upgrade

This is all configured using both ...

memory_limit = 1024M

in /etc/php.ini as well as ...

define('WP_MEMORY_LIMIT', '1024M');
            } else {
                    define('WP_MEMORY_LIMIT', '1024M');
            }
    }

    if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
            define( 'WP_MAX_MEMORY_LIMIT', '1024M' );
    }

in ~/wp-includes/default-constants.php.

This obviously leads me to believe there's a memory leak somewhere which have to be solved, but how would I go about to find this when everything's prepackaged Wordpress stuff? Here's some excerpts from top ^M when pushing the Update button:

Before

Mem:   1034656k total,   235836k used,   798820k free,     6388k buffers
Swap:  2048248k total,   107940k used,  1940308k free,   139156k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
23649 apache    19   0  160m  22m  15m S  0.0  2.2   0:07.06 httpd

While

Mem:   1034656k total,  1020396k used,    14260k free,       60k buffers
Swap:  2048248k total,   152484k used,  1895764k free,    26880k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
23645 apache    21   0 1079m 906m  16m R 75.5 89.7   0:06.95 httpd

Wordpress version 4.2

MySQL 5.1

Apache 2.2.22

Installed plugins: Hello Dolly 1.6 and Akismet 3.1.1


This is the output from strace -f -r exactly where it stalls:

29638 0.000134 writev(16, [{"28\r\n", 4}, {"<p>Enabling Maintenance mode&#82"..., 40}, {"\r\n", 2}], 3) = 46 29638 0.000122 time(NULL) = 1436025429 29638 0.000060 getcwd("/var/www/foobar/wp-admin"..., 4096) = 32 29638 0.000064 time(NULL) = 1436025429 29638 0.000040 open("/tmp/php9Ldioo", O_RDWR|O_CREAT|O_EXCL, 0600) = 19 29638 0.000061 getpeername(18, {sa_family=AF_INET, sin_port=htons(21), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0 29638 0.000068 poll([{fd=18, events=POLLOUT}], 1, 240000) = 1 ([{fd=18, revents=POLLOUT}]) 29638 0.000038 send(18, "PASV\r\n", 6, 0) = 6 29638 0.000078 poll([{fd=18, events=POLLIN|POLLERR|POLLHUP}], 1, 240000) = 1 ([{fd=18, revents=POLLIN}]) 29638 0.000119 recv(18, "227 Entering Passive Mode (127,0"..., 4096, 0) = 45 29638 0.000048 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 20 29638 0.000029 fcntl64(20, F_GETFL) = 0x2 (flags O_RDWR) 29638 0.000025 fcntl64(20, F_SETFL, O_RDWR|O_NONBLOCK) = 0 29638 0.000026 connect(20, {sa_family=AF_INET, sin_port=htons(8721), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) 29638 0.000060 poll([{fd=20, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 240000) = 1 ([{fd=20, revents=POLLOUT}]) 29638 0.000039 getsockopt(20, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 29638 0.000028 fcntl64(20, F_SETFL, O_RDWR) = 0 29638 0.000024 poll([{fd=18, events=POLLOUT}], 1, 240000) = 1 ([{fd=18, revents=POLLOUT}]) 29638 0.000036 send(18, "NLST /.maintenance\r\n", 20, 0) = 20 29638 0.000053 poll([{fd=18, events=POLLIN|POLLERR|POLLHUP}], 1, 240000) = 1 ([{fd=18, revents=POLLIN}]) 29638 0.000187 recv(18, "150 Here comes the directory lis"..., 4096, 0) = 39 29638 0.000111 poll([{fd=20, events=POLLIN|POLLERR|POLLHUP}], 1, 240000) = 1 ([{fd=20, revents=POLLIN}]) 29638 0.000037 recv(20, "", 4096, 0) = 0 29638 0.000024 close(20) = 0 29638 0.000038 lseek(19, 0, SEEK_SET) = 0 29638 0.000026 read(19, "", 8192) = 0 29638 0.000031 close(19) = 0 29638 0.000023 unlink("/tmp/php9Ldioo") = 0 29638 0.000042 poll([{fd=18, events=POLLIN|POLLERR|POLLHUP}], 1, 240000) = 1 ([{fd=18, revents=POLLIN}]) 29638 0.000037 recv(18, "226 Directory send OK.\r\n", 4096, 0) = 24 29638 0.000063 poll([{fd=18, events=POLLOUT}], 1, 240000) = 1 ([{fd=18, revents=POLLOUT}]) 29638 0.000038 send(18, "CWD /.maintenance/\r\n", 20, 0) = 20 29638 0.000035 poll([{fd=18, events=POLLIN|POLLERR|POLLHUP}], 1, 240000) = 1 ([{fd=18, revents=POLLIN}]) 29638 0.000067 recv(18, "550 Failed to change directory.\r"..., 4096, 0) = 33 29638 0.000050 poll([{fd=18, events=POLLOUT}], 1, 240000) = 1 ([{fd=18, revents=POLLOUT}]) 29638 0.000037 send(18, "PWD\r\n", 5, 0) = 5 29638 0.000052 poll([{fd=18, events=POLLIN|POLLERR|POLLHUP}], 1, 240000) = 1 ([{fd=18, revents=POLLIN}]) 29638 0.000035 recv(18, "257 \"/\"\r\n", 4096, 0) = 9 29638 0.000047 poll([{fd=18, events=POLLOUT}], 1, 240000) = 1 ([{fd=18, revents=POLLOUT}]) 29638 0.000036 send(18, "RMD /.maintenance\r\n", 19, 0) = 19 29638 0.000059 poll([{fd=18, events=POLLIN|POLLERR|POLLHUP}], 1, 240000) = 1 ([{fd=18, revents=POLLIN}]) 29638 0.000035 recv(18, "550 Remove directory operation f"..., 4096, 0) = 40 29638 0.002773 brk(0x929f000) = 0x929f000 29638 0.001533 brk(0x92df000) = 0x92df000 29638 0.001396 brk(0x931f000) = 0x931f000 29638 0.001436 brk(0x935f000) = 0x935f000 29638 0.001488 brk(0x939f000) = 0x939f000 29638 0.001460 brk(0x93df000) = 0x93df000 29638 0.001388 brk(0x941f000) = 0x941f000 29638 0.001452 brk(0x945f000) = 0x945f000 29638 0.000772 brk(0x949f000) = 0x949f000 29638 0.000668 brk(0x94df000) = 0x94df000 29638 0.001326 brk(0x951f000) = 0x951f000 29638 0.001320 brk(0x955f000) = 0x955f000 29638 0.001423 brk(0x959f000) = 0x959f000 29638 0.001508 brk(0x95df000) = 0x95df000 29638 0.001410 brk(0x961f000) = 0x961f000 29638 0.000280 brk(0x965f000) = 0x965f000 /29638 0.001073 brk(0x969f000) = 0x969f000 29638 0.001342 brk(0x96df000) = 0x96df000 29638 0.001341 brk(0x971f000) = 0x971f000 29638 0.001389 brk(0x975f000) = 0x975f000 29638 0.001385 brk(0x979f000) = 0x979f000 29638 0.001172 brk(0x97df000) = 0x97df000

0

3 Answers 3

3

It looks like an infinite loop as line 159 of wp-admin/includes/file.php is a recursive call to the function wp_tmpnam(). It breaks the update process, so may be it could be worth checking this small correction, which describes your problem : wordpress bug fix

1
  • 1
    @Lars Glad it helped, you're welcome!
    – Zimmi
    Jul 5, 2015 at 10:00
3

The memory leak (or just high memory usage) is almost always because of Wordpress.

Wordpress is a well known memory and CPU hog, especially if you are using bad plugins and templates.

You may try to disable all the plugins and templates one by one until you find which one is causing the high memory usage and replace it with another similar one or report the problem to its author to fix it for you.

If you are not a WP developer and don't know PHP then there is not much else you can do to fix the actual problem causing high memory usage.

There are a few cases where some PHP module would cause similar behavior or would simply segfault. If disabling everything on WP doesn't change anything you could try disabling PHP's modules one by one to see if anything changes.
Especially modules that have to do with caching (eg Xcache, APC, eAccelerator, etc)

If you do know PHP and would like to go a little bit deeper you could also install xhprof module for PHP to be able to do profiling on wordpress as it runs to see which methods, functions etc take up all the memory and go from there.

2

Since you do not have any addition plugins, I still suggest you to follow below steps:

  • Disable both plugins
  • Switched to default WordPress themes
  • Scan all contents using virus scanner

Then try to update contents. If it is still consuming lots of memory, it may be server configuration issue.

1
  • I disabled everything I could yet the problem persists, it even happens if I want to update a single tiny plugin and not the whole Wordpress installation, surely that'd be a sign there's something fishy in the update procedure somehow?
    – Lars
    Jul 4, 2015 at 14:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .