Super facile grâce à l'extension PECL win32service et ma classe win32_service - vous en trouverez la documentation ici.
Pour le monitoring ce qui de l'environnement, ce script repose sur la presence du tookit yks que j'ai déjà présenté dans ma précédente contribution.
/*
php mydaemon.php install
REM #Service 'myhost_survey' sucessfully installed
php mydaemon start
REM #Service 'myhost_survey' sucessfully started
php mydaemon status
REM #Service 'myhost_survey' is running
php mydaemon stop
php mydaemon uninstall
REM #Service 'myhost_survey' sucessfully uninstalled
*/
class myhost_survey extends win32_service {
var $test_url = "http://check.myhost.com/server.status?auto";
const ping_challenge = 'pong';
function run(){
try {
$res = http::ping_url($this->test_url);
if($res != self::ping_challenge)
throw new Exception("Invalid response $res");
} catch(Exception $e) {
$this->wake_up_neo("Server ping is down {$this->test_url}".$e->getMessage());
}
}
function wake_up_neo($message){
try {
$res = sms::send_message("0698675432", $message);
} catch(Exception $e){
die("Error manager reports an error, you won");
}
die;
}
}
new myhost_survey($argv[1]);