Slow wp-admin; 500 error admin-ajax.php; M1 Macbook

I’m using DevKinsta on a new macbook pro (M1). The front-end of one of the websites loads fine, but the wp-admin back-end is painfully slow, sometimes taking 20-30 seconds to load a page.

Additionally (and more importantly), with one specific website, I get a 500 error on admin-ajax.php that prevents using the Elementor plugin entirely. This is the error I’m getting in the browser console:
Failed to load resource: the server responded with a status of 500 () /wp-admin/admin-ajax.php:1

When I check the nginx error log, I see the following error:

2021/08/27 22:21:31 [error] 102#102: *195 FastCGI sent in stderr: “PHP message: PHP Fatal error: Out of memory (allocated 62164992) (tried to allocate 7751200 bytes) in /www/kinsta/public/corneacare/wp-content/plugins/elementor/core/common/modules/ajax/module.php on line 265” while reading response header from upstream, client: 172.18.0.1, server: corneacare.local, request: “POST /wp-admin/admin-ajax.php HTTP/2.0”, upstream: “fastcgi://172.18.0.3:9002”, host: “corneacare.local”, referrer: “https://corneacare.local/wp-admin/post.php?post=975&action=elementor

I’ve increased the max_execution_time in php to 1200, increased max_input_time to unlimited (-1), and increased memory_limit to a whopping 2048, and I still get the same error.

I’ve also tried editing and adding some rules to the nginx config:
fastcgi_buffers 16 32k;
fastcgi_buffer_size 64k;
fastcgi_read_timeout 600;

After restarting php-fpm and nginx from the docker dashboard, none of these changes seem to have any effect.

I’ve also tried disabling every plugin aside from Elementor, and the problem persists.

This is a site that’s cloned from Kinsta, and it works very fast, with no errors, on the live Kinsta host. It also works fine in my homespun local dev environment on my old macbook. So this issue seems to be isolated to the DevKinsta environment.

Welcome to DevKinsta @Chronic_Pete ! I’m happy to help.

Could you try creating a file called phpinfo.php inside your sites directory structure and put in the following lines on that file?

<?php
phpinfo();
?>

Then load the file on your browser and tell me if the values you’ve updated are being applied.

Hi @michael!

Thanks for the [should-be obvious] troubleshooting suggestion. The values aren’t being applied.

By the way, in order to change those values, I opened the CLI for devkinsta_fpm, using the CLI button in the devkinsta dashboard. I installed vim on that container, edited the file at /etc/php/7.4/fpm/php.ini (this site is using 7.4), closed and saved the file, and restarted the container from the docker dashboard using the restart button.

@michael - I also tried switching that website to PHP 8.0 via the devkinsta interface, editing the php.ini file at /etc/php/8.0/fpm, and restarting php via the docker restart devkinsta_fpm command. When I reloaded the phpinfo page, it still shows PHP Version 7.4.18 as the php version, and none of the settings are updated.

Thanks for testing that. Seems like there’s a larger issue here as changing PHP versions should be working by default without any changes.

Try exiting out of DevKinsta, delete the devkinsta_fpm container, and reload DevKinsta so it can create it again. Then test changing versions again to see if that helps. Deleting the devkinsta_fpm won’t erase any of the data.

Thanks @michael. I just did what you suggested. It did switch the version of php up to 8.0.5. I then tried changing those values again, and restarting the php container. The changes still didn’t take. Then I updated and upgraded all of the server packages, tried altering the values in php.ini again, and it still won’t work. I double-checked to make sure there’s only one instance of devkinsta_fpm in docker desktop, and I’ve confirmed that.

One interesting thing to note: I’ve gotten that out of memory error even when the allocated memory was far higher than the memory that it was trying to allocate:
2021/08/31 16:59:56 [error] 76#76: *73 FastCGI sent in stderr: "PHP message: PHP Fatal error: Out of memory (allocated 62164992) (tried to allocate 32768 bytes)

I’ve had very similar behavior on a DevKinsta website.

I deleted the two files wp-content/advanced-cache.php and wp-content/object-cache.php + the wp-rocket plugin on the local dev site. After that, my local site did not throw “out of memory” errors anymore.

Maybe this helps you as well.

About the php.ini changes:

Try this command in the docker CLI:

grep memory_limit /etc/php/7.4/fpm/**/*.ini

You will see that there is another config file (tuning.ini) that overwrites the default php.ini value for “memory_limit”

Solution: Create a new config file with a prefix like “zz” - the ini files are loaded in alphabetical order and files that are loaded later will overwrite settings of earlier files:

vim /etc/php/7.4/fpm/conf.d/zz-custom.ini

# set your custom memory_limit / other PHP settings here and restart the FPM container

Btw, I just came across this report here: Memory Leak on M1 Macs · Issue #5204 · docker/for-mac · GitHub. Seems like Docker for Mac + PHP + M1 has some issues.

Thanks @philippstracker. I don’t have that plugin installed, but overriding the php.ini settings in the conf.d files was a great find! I did manage to get those changes to take effect, but unfortunately, I’m getting the out of memory error no matter how much memory I give php-fpm. I’ve increased it to 2G and the error still occurs.

I also installed wp cli on the devkinsta_fpm container, optimized the db and deleted expired transients. That didn’t fix the issue either.

This issue is isolated to this one instance within devkinsta, too. I have another dummy site set up in devkinsta with Elementor, which wasn’t imported from Kinsta hosting. The error isn’t occurring there. I’ll continue to troubleshoot and if I figure out what’s going on I’ll post it here in case anyone else has the same problem.

I tried to recreate this site in devkinsta manually instead of pulling it from Kinsta, but when I imported the database that I’d exported from kinsta’s phpmyadmin, it crashed the nginx server in devkinsta.

That’s odd :thinking: . I’ll keep researching this one and will report back soon!

@michael very strange indeed. After all of the workarounds I’ve tried, I think this might have something to do with the memory link in Docker Desktop on M1 macs that @philippstracker mentioned above. Docker says they’ve resolved the issue but it tracks with some of the comments in that thread in github.

This user’s workaround swapped out some x64 libs with ARM libs. If I want to try this, where would I find the appropriate Dockerfile on my machine?

@Chronic_Pete What version of Docker do you have? Docker 4.0.0 for MacOS was released a couple days ago. If you don’t have that version, could you try updating and let me know if that works for you?

@michael I have 4.0.0 (67817)

Hey @Chronic_Pete . We’ve been testing on Apple M1 machines and haven’t been able to reproduce the issues here (so far). It’s a bit odd that it’s only occurring on one site. Have you already tried to re-import the site?

Hi @michael - Yeah, I’ve had to delete and re-import the site several times per week - there’s another person working on the content side, so I often need to update my local environment. When I’ve tried to just import the database, it crashes the nginx server in Docker. So the only way I can do this with DevKinsta is to back up the theme (to be safe), delete the local site from within DevKinsta, and re-import it using the DevKinsta import tool. It would be much easier if I could just update the local db.

Another idea for a workaround:
I’m using WP Migrate DB Pro to keep local/stage/live websites in sync. Maybe this is an option for you - it is very reliable and fast.

Hey @Chronic_Pete. Could you try DevKinsta 2.3.0 and let me know if this issue continues?