Ubuntu LAMP config: Web Pages suddenly responding very slowly 15-20 seconds via PHP; but plain .html and .jpg files seem to load quickly

Hello. We are running WordPress on a Linode with Ubuntu and LAMP setup.

Everything seemed relatively okay as of Tuesday, but as of Wednesday morning, there's a lag when a request is made to our site. It takes about 20 seconds for the page to begin downloading and rendering.

I deactivated all the possible Plugins in Wordpress, rebooted the Linode, rebooted Apache, did updates and upgrade dist for Ubuntu. And the lag is still there.

I made a 1 line php test file that echos a message, and it loads slowly.

I made test .html pages and also tried to access .jpg files, and they both loaded fine, plenty quick.

So, I think something is mysteriously wrong with the pages that are scripts.

Nobody changed anything on the server one day to the next.

How might I begin to figure out where the problem might be? Thanks

2 Replies

While there are many reasons a website can be slow, since you mention PHP specifically, I'd recommend looking into that service as a starting point.

I found a discussion on ServerFault about PHP loading slowly. That issue turned out to be caused by PHP hitting it's max_children limit. This means that there are too many concurrent PHP processes, so any new ones would be backlogged, which could cause the issues you're seeing.

This post should help if you don't know where to find your PHP error logs, which may be stored in different directories on different distributions. Here are some additional resources about checking log files if you need it:

Since this could be an issue with memory, I'd also recommend investigating your system's memory usage.

I'd also recommend checking to see how your system is prioritizing PHP. Use the top command and see what the nice value is for PHP to ensure your system isn't for some reason deprioritizing it more than you'd like.

Finally, here are some general guides for help with Apache and general slow website issues if PHP turns out to not be the culprit.

I don't know what your PHP settings are but you might set them to the following. If you change the php.ini you need to restart Apache if using mod-php or just php if using FPM.

You could also use .user.ini as well but I've not always had good results with that.

I suggest trying it in .htaccess first. Put this stuff above the Wordpress stuff.

In php.ini

memory_limit = 512M
max_execution_time = 900
max_input_time = 900
post_max_size = 256M
upload_max_filesize = 720M

In .htaccess

php_value memory_limit 512M
php_value max_execution_time 900
php_value max_input_time 900
php_value post_max_size 256M
php_value upload_max_filesize 720M

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct