The problem:
I made a script that every minute - it restarts a program if it is told to in a mySQL database as well as if the program is not responding. I created it without a problem; it worked in the terminal, PHP and so on. Then why won't it work in Crontab? What my server's doing to the PHP file is simple - it wants to miss half of the script out! Instead of checking if the server is offline, it just automatically starts yet another process.
The code:
#!/usr/bin/php
<?php
/* Make sure the user can execute commands... */
putenv('SHELL=/bin/bash');
/* Read the mySQL database */
$sql_info = "SELECT * FROM servers";
$result_info = mysql_query($sql_info);
while($row = mysql_fetch_array($result_info, MYSQL_ASSOC))
{
$m_pid = exec("pidof ".$row['server_exe']);
if(!$m_pid)
{
if($row['auto_restart'])
{
$shellw = "cd ".$row['server_dir']." ; su nobody -c ./".$row['server_exe']." &";
proc_close(proc_open ($shellw, array(), $foo));
echo "Started server: ".$row['server_owner']."\n";
}
}
}
mysql_close($conn);
?>
Brainwave: Would I need to use Bash in order to get the process ID?