Krydos Posted July 26, 2017 Posted July 26, 2017 I'm going to change the password on your cpanel account to test this. Don't panic. I'll post in this thread when I'm done and you can change the password back.
Krydos Posted July 26, 2017 Posted July 26, 2017 Alright, I'm done testing. You can change your Tommy cpanel password back, and you can also change your luigi123_sb mysql user password back to what it was before. Here's your tested script:<?php $db_host = "localhost"; $db_user = "luigi123_sb"; $db_pass = "bestpasswordever"; $con = new mysqli($db_host, $db_user, $db_pass); if ($con->connect_error) die("Connection failed: ".$con->connect_error); $sql = "select * from information_schema.processlist"; $result = $con->query($sql); while ($row = $result->fetch_assoc()) { $command = $row['COMMAND']; if ($command == "Sleep") { $mysql_id = $row['ID']; $con->query("kill $mysql_id"); } } Put this somewhere in public_html and make sure you set the password for luigi123_sb properly. Even if your mysql user is at the max open connections this command will still function. It will scan through all of your open connections and if their status is sleeping it closes them. You can execute it manually by visiting the page in your browser or I can set up an external cron to run every 5 minutes or something. Hopefully this helps.
Luigi123 Posted July 26, 2017 Author Posted July 26, 2017 What do you want me to name the file for the script? And do I have to change the password for luigi123_sb in the script after I save it? Also, what do you want me to save the file as type?
wolstech Posted July 26, 2017 Posted July 26, 2017 You should be able to copy that into a plain text file and name it anything, as long as it has a .php extension. It's just a regular php file. It needs to be saved somewhere inside the public_html so its accessible from the web, or you won't be able to run it. To run it, just visit it in your browser. The database account settings are right at the top. Just set the username/password you use for the database between the " ". The host should stay as localhost.
Luigi123 Posted July 27, 2017 Author Posted July 27, 2017 Do I change the password back for luigi123_sb where it was in the script?
wolstech Posted July 27, 2017 Posted July 27, 2017 Yes. Whatever the password is for that user in cpanel, should also be in that variable at the top of the script. They have to match.
Krydos Posted July 27, 2017 Posted July 27, 2017 In order to test the script I changed the password of luigi123_sb so you'll need to change it back to whatever it was before so your gameserver will be able to connect to the database.
Luigi123 Posted July 28, 2017 Author Posted July 28, 2017 Alright, when I go to edge-gamers.heliohost.org/scripts/script-for-sourcebans.php, there's nothing happen. It just blank page. Did I do something wrong?
Krydos Posted July 28, 2017 Posted July 28, 2017 No, there is no output to the screen as the script is meant to be run from cron. You can add this line if you want it to print something to the screen:<?php $db_host = "localhost"; $db_user = "luigi123_sb"; $db_pass = "bestpasswordever"; $con = new mysqli($db_host, $db_user, $db_pass); if ($con->connect_error) die("Connection failed: ".$con->connect_error); $sql = "select * from information_schema.processlist"; $result = $con->query($sql); while ($row = $result->fetch_assoc()) { $command = $row['COMMAND']; if ($command == "Sleep") { $mysql_id = $row['ID']; $con->query("kill $mysql_id"); echo "Killed mysql process $mysql_id. "; // <---- This is the new line } }
Luigi123 Posted July 28, 2017 Author Posted July 28, 2017 Oh, no wonder. Can you run the cron for me for every 5 mins or something?
Krydos Posted July 28, 2017 Posted July 28, 2017 A cron executes https://edge-gamers.heliohost.org/scripts/script-for-sourcebans.php every 5 minutes now.
Recommended Posts