Jump to content

[Solved] Close The Connections For Luigi123_Sb


Luigi123

Recommended Posts

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

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.
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
  }
}
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...