Jump to content

Recommended Posts

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

Posted

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.

Posted

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.
Posted

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?

Posted

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.

Posted

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.

Posted

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.

Posted

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?

Posted

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
  }
}
Guest
This topic is now closed to further replies.

×
×
  • Create New...