Skip to content

Instantly share code, notes, and snippets.

@casparjones
Last active December 14, 2015 08:29
Show Gist options
  • Save casparjones/5058435 to your computer and use it in GitHub Desktop.
Save casparjones/5058435 to your computer and use it in GitHub Desktop.
simple php daemon
<?php
if($argv[1] == '-d') {
echo "start daemon\n";
while(true) {
if(file_exists('message.txt')) {
$oMessage = json_decode(file_get_contents('message.txt'));
if($oMessage->action == 'sayHello') {
echo "Hello...\n";
}
if($oMessage->action == 'exit') {
echo "exit daemon\n";
unlink('message.txt');
die();
}
unlink('message.txt');
}
}
}
if($argv[1] == '-sayhallo') {
$oMessage = new stdClass;
$oMessage->action = 'sayHello';
file_put_contents('message.txt', json_encode($oMessage));
}
if($argv[1] == '-exit') {
$oMessage = new stdClass;
$oMessage->action = 'exit';
file_put_contents('message.txt', json_encode($oMessage));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment