Apache – PHP Scripts Suddenly Load Very Slow on Apache

apache-2.4php-fpmubuntu-20.04

I am testing why sometimes my PHP scripts takes long to load over network (>30sec) on my Apache 2.4 Ubuntu server with PHP-FPM 7.4 using mpm_event. The server was working normally in the past few months, this started happening a few days ago and I didn't change anything. I did a reboot, it didn't help.

I've made a simple test.php. Sometimes it loads normally (<100ms), but sometimes it takes 1 minute to load:

<?php echo "test\n"; ?>

enter image description here

  • Server's CPU, RAM and IO are all normal (checked with htop).
  • Static HTML files are loaded without any delays.
  • Running script locally via SSH console is very fast.
  • Apache error logs doesn't show anything unusual.
  • I checked if there is some DDOS attack by checking the number of connected IPs from same /16 subnet and didn't find anything weird (e.g. >100 connections).

How can I debug this further to see why this is happening?


Some debug output which may help:

sudo service php7.4-fpm status

enter image description here

Best Answer

There may be several reasons for this behavior:

  1. If this web server processes requests from the external network, then with the increase in the amount of traffic, the load could increase, which led to an increase in the server response time.
  2. If your scripts use calls to external resources, then in this case the response time of your server may increase due to the low response speed of the external resource.

Log message:

[30-Sep-2021 03:36:46] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it

is just proof of the increased load.

In both cases, you should determine the reasons for the load by analyzing the number of requests to the scripts, and if there are calls to external resources, make sure that they work correctly.

Related Topic