1

I have a situation when some DDOS attacks are putting my PHP server down. Occasionally.

I'm using AWS with auto scaling groups, so it is not a problem.

The problems start when this server is going down in the middle of the cron job scheduled PHP script.

So my idea was to block all of the routs on the PHP servers except for the /healthcheck...

How can I do that and is there a better solution?

4
  • How to protect a php server from going down when the php script is running? Nov 27, 2020 at 4:39
  • As an option, I would suggest you to load routes depends on env variable which will be true when cron job starts and false when it's finished. To be sure that this variable will be false even on cron script fails I would wrap the whole script with try/finally. Instead of env variable can be used any in-memory data structure store like redis/file even APC Nov 27, 2020 at 6:02
  • Are you querying the DB? If yes then your query could be a problem. Check for any slow query. See if you can create indexes in the columns which you use with where clause. A combination of the above points helped me in a similar problem.
    – Krish
    Nov 27, 2020 at 6:13
  • Do you have request throttling in place? You can add somthing like throttle:60,1 to your route(s) middleware to limit a client to 60 requests in a 1 minute window.
    – Brian Lee
    Nov 27, 2020 at 6:25

1 Answer 1

1

have you considered creating secondary auto scaling group, specifically for the cron job? It would require setting up Scheduled Action like this:

  1. use this same launch config as your current auto scaling group
  2. setup second auto scaling group with "Scheduled actions" set to start the server (min / max / desired set to 1) at specific time
  3. update your cron with AWS CLI call to terminate the instance once completed by setting min / max / desired set to 0 on the newly created scaling group

that way live system and cron jobs are separated and will not affect one another.

3
  • Thank you. It sounds like a good idea. I can use the same source code base with some config params telling the system - where to run the cron scripts and where to avoid running them. It would be better then stopping the traffic on the ALB for the cron job running instance... Nov 29, 2020 at 22:11
  • Thank you for your answer, but is there more options to try, like AWS Batch, AWS Glue...? Nov 29, 2020 at 22:35
  • That very much depends on what the from job is doing. Saying this, given your description, second ASG sharing same launch configuration and AMI would probably be easiest.
    – Tomek Klas
    Dec 9, 2020 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.