Shutdown / reboot bir LAMP üzerinde bir PHP script (MYSQL / w) Run

0 Cevap php

I need to execute a PHP script at a LAMP shutdown/reboot. The script will update the state of local server on Mysql databases running on remote servers.

<?php
print "Updating Hosts...";
mysql_connect('localhost','ivo','andream');
mysql_select_db('ecom');
$query = "SELECT * FROM companies"; 
$result=mysql_query($query);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
    $remote=mysql_result($result,$i,"sito");
    $remdbport=mysql_result($result,$i,"dbport");
    $remhost = ''.$remote.':'.$remdbport.'';
    $remdb=mysql_result($result,$i,"database");
    $remusr=mysql_result($result,$i,"remusr");
    $rempswd=mysql_result($result,$i,"rempswd");
    $rconnect=mysql_connect($remhost,$remusr,$rempswd);
    mysql_select_db($remdb,$rconnect);
    $query = "UPDATE lareaclient SET serverstate = '0' WHERE kiave = 'workarea'";   
    $resultloop=mysql_query($query);
        mysql_close($rconnect);
    $i++;
}
mysql_close();
print "Hosts updating complete";
?>

CLI bu şekilde başlattığı script iyi çalışıyor:

root@server:/home/mylamp# lynx -dump https://ecom.anys.info/private/serverstatedown.php

but it seems not to work at shutdown or reboot. I've included the same CLI in a bash script on both runlevels 0 and 6 with

root@server:/home/mylamp# update-rc.d apache1 start 01 0 6 

but nothing happens.
My idea is that Mysql service stops before the PHP script be executed. Is that wrong? Any idea?

0 Cevap