Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

joydasolive's avatar

AWS EC2 server cpu spike on PHP-FPM process

We have a EC2 server which was doing fine until this morning. Suddenly, the CPU reached near 100% and stayed there consistently. I looked at the FPM logs:

server reached pm.max_children setting (5), consider raising it.

I did raise it and changed some values as well.

pm.max_children = 40 pm.start_servers = 15 pm.min_spare_servers = 15 pm.max_spare_servers = 25 pm.max_requests = 500

But the CPU is still 100%.

The PHP-FPM7.1 is taking all the CPU. The memory usage is minimal.

Before this morning, it was always below 10-20% for the last few months.

The server is created and deployed by Laravel Forge.

It has 2 Cores and 8GB RAM.

Anyone could shed a light on this please.

0 likes
9 replies
bashy's avatar

Have you got any code that could possibly be looping and taking memory?

You obviously can't keep raising the limits since it's just going to fill it.

2 likes
joydasolive's avatar

I haven't deployed any new code in the last few days. No one had any access to server. It was fine until 11.40am this morning and then a sudden jump.

joydasolive's avatar

Also the DB is hosted on RDS and the CPU there is high as well. It was around 10% and then jumped at the same time to around 50-60%.

Cronix's avatar

Might look at the network traffic to your box. Sounds like someone could be flooding you with requests.

joydasolive's avatar

It looks like it. I had someone look into it and he said it could be DDOS on EC2 as well as RDS.

I am not sure about the security groups. Can someone help me on that please.

Basically this is the server forge created and I left the security rules as they were.

This is the security group sg-bd34ffda (default) for EC2. Inbound rules:

All TCP TCP 0 - 65535 0.0.0.0/0 All traffic All All sg-bd34ffda (default) All UDP UDP 0 - 65535 0.0.0.0/0

The inbound rules for RDS:

MYSQL/Aurora TCP 3306 sg-bd34ffda (default)

The sites hosted all using https. So I don't even need to listen to http.

Is there any way to mitigate this attack? I am not using Cloudfare or Route53. Just a elastic IP address and A record on specific sites.

Any help will be appreciated.

themadsicilian's avatar

Hi @joydasolive,

From what you describe above it sounds like the instance forge created is full open to the internet which invites mischievous activity. These networks are routinely scanned by botnets for open, exploitable ports so I would definitely work towards making this "least privileged". Depending on the age of the instance, you definitely want your servers in a minimal VPC. This is really an exercise of security groups and network ACLs. They also introduced https://aws.amazon.com/shield/ late last year which I believe you only get if you're in a VPC (not EC2 classic).

Are you using an ELB/ALB load balancer? If so do you see an increase in requests in the ELB logs or on the server (apache/nginx)?

Which instance type are you on? Some of the lower instance types operate on a CPU credit system that I've seen act up when the allowance is exhausted. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-instances.html

joydasolive's avatar

Yes, it was open to the internet to all ports and I think it was most likely UDP flood that caused it. On top of that, lots of rows were deleted from the DB few days earlier than the attack and slowly the queries were taking longer. Both contributed to the high usage of CPU.

I am on VPC and now locked down the access to all ports apart from http(s) and only allow SSH to me and Forge. I also optimized the DB so the query time is quicker.

Will probably look into Shield if it comes back through different medium.

I am on m4.large which should be good enough for my case as I have the DB hosted elsewhere and the number of users are not big enough.

Thanks everyone for your input, really appreciated.

2 likes

Please or to participate in this conversation.