I am looking for a PHP script which can check mysql is running or not in CENTOS / Linux VPS
?
I have tried several method but its not working
First Method:
<?
$command = ('/etc/init.d/mysql restart');
if (! $dbh = mysql_connect('localhost','username','password') ){
$output = shell_exec($command);
echo "<pre>$output</pre>";
}
else
echo"nothing happened";
?>
Second Method:
<?php
// STOP + START = RESTART..
system('net stop "MySQL"'); /* STOP */
system('net start "MySQL"'); /* START */
?>
Both Methods dint not works for me in PHP..
Problem Is : these days my site having too much load of mysql, i tried several method but i am unable to stop its crashing. therefore i decide to make a PHP script to check weather mysql is running or not? If not then PHP script will perform Restart Mysql, or else print "My Sql is running". for this I've decided to set a Cron Job in PHP, that PHP script will monitor mysql is running or not. I am also looking to save the logs in the end.. to check how many times mysql got restart..... please someone find the fix of this issue.. and post here.. thanks in advance...