0

I’d like to know if there is a PHP/MySQL configuration option (or combination of options) that can prevent long-running PHP scripts in a small number of places from creating hanging and sleeping MySQL transactions that accumulate and can cause the entire MySQL server to crash.

Here’s the scenario I’m looking to avoid:

Let’s say I've launched a new site and one of the sections has a really inefficient PHP loop that never got addressed or was unforeseen. Once the site launches and it sees a huge amount of traffic the query rears its head and we receive 504 errors.

At this point we're accumulating a massive amount of sleeping MySQL connections and, if we hit our max connection limit, it brings down the database server and the rest of the site with it. All because one query on one page.

What I'm hoping to do is to prevent badly performant Twig/PHP code from having even the possibility of bringing down the server. Some mechanism or set of server config options that would cause the user on just that page to see an error, preventing hanging transactions, and keeping the database from a catastrophic failure that would affect everyone else.

I’m aware that, ultimately, the query itself needs optimization. But what I’d like to do is setup preventative measures that keep the servers from crashing for the other users on the site.

Does something out there exist to prevent this?

  • Please post your PHP code that is responsible for CONNECT, PROCESS, CLOSE for analysis. Sounds like you are missing the CLOSE. – Wilson Hauck Sep 26 '20 at 19:09
  • Sorry, @WilsonHauck, I don't have a particular PHP example for this question. I'm hoping to find an answer that's ubiquitous here and more code/platform agnostic. If it's helpful, this could be an unoptimized, long-running Laravel transaction that triggers a 504 and begins pooling sleeping/hanging MySQL connections. – Aaron Bushnell Sep 26 '20 at 19:44
  • Some database problems _must_ be solved at the application level. – Rick James Sep 27 '20 at 16:06

0 Answers0