How to build reliable MySQL connection on server start?
Hi,
rarely I'm receiving the following error: "Can't connect to MySQL server" right after server restart (sometimes). My SQL DB is external. I don't think there is any problem with hoster. sm: 1.10.6454 Log:
Spoiler
PHP Code:
2) Do I need to close handle on plugin end? 3) What is a best practice to keep db connection alive? How sm handle this, e.g. when connection established and it was lost for some time (several sec. or so)? 4) Did I accomlished it correctly (in reliability meaning) so I close(?) connection on round_end (and Map End) and restore it again each time? |
Re: How to build reliable MySQL connection on server start?
I don't think that you need to reconnect to DB on every round.
Also, you don't need to close DB handle on plugin end, because SourceMod does it for you automatically. |
Re: How to build reliable MySQL connection on server start?
If the db fails during connection I wouldnt bother reattempting connect.
Connect once on plugin start and thats it. Your connection will stay alive. |
Re: How to build reliable MySQL connection on server start?
So, any ideas why that error sometimes happens on server start?
I can't believe in coincidence. I have no problems with DB hoster / or other connection errors during gameplay. One of those 20 attemps each 3 sec. definitely should have been successful. Quote:
|
Re: How to build reliable MySQL connection on server start?
Connect to the database when the plugin starts and save the db globally. If you lose connection, there's no need to reconnect.
|
Re: How to build reliable MySQL connection on server start?
Quote:
Quote:
|
Re: How to build reliable MySQL connection on server start?
Quote:
Just connect to the database OnMapStart (or OnConfigsExecuted) and check if the db is null. PHP Code:
|
Re: How to build reliable MySQL connection on server start?
Ohh, I understand that from the first answer of MAGNAT. Thank you.
That doesn't explain why "Can't connect to MySQL server" error happen on server start. |
Re: How to build reliable MySQL connection on server start?
Your DB might be overloaded with slow queries (that's not 100% true, but you should try to dig this way).
I had similar problem when used non-threaded queries (like DBStatement Execute inside loop) without DB Lock. EDIT: There can be several problems: 1) DB server might be stopped (or disabled). Just check server status. 2) Firewall may be blocking your connections. 3) Wrong login or/and password (or configuration generally). 4) DB User doesn't have permissions. 5) Check slow queries log. Also try to run some queries to see if your DB server responds normally. |
Re: How to build reliable MySQL connection on server start?
Thanks for help.
Plugin written with threaded queries only. DB is free of loading most of the time. 1) Report from hoster panel: no incidents during that week. 2) 3306, 5432 ports are on firewall exclusions. 3) It is correct. 4) User has permissions. 5) Dunno how and where logs are stored. But, I'll try found acrticles on it. MySQL Query browser answer: Quote:
Very appreciate, if you have more thoughts. |
All times are GMT -4. The time now is 07:46. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.