I'm mucking about with daemons, and wondered how feasible (in terms of memory and cpu usage, and reliability) it is to do this using PHP:
<?php
// Ignore user aborts and allow the script
// to run forever
ignore_user_abort(true);
set_time_limit(0);
$fp = fopen('loop.log', 'w');
fwrite($fp, date('Y-m-d H:i:s') . ' Started' . PHP_EOL);
while(1) {
fwrite($fp, date('Y-m-d H:i:s') . ' Looped' . PHP_EOL);
if (file_exists('loop.stop')) {
break;
}
// Sleep for 100 seconds
sleep(100);
}
fwrite($fp, date('Y-m-d H:i:s') . ' Stopped' . PHP_EOL);
fclose($fp);
This simple example (adapted from the PHP manual for ignore_user_abort) is just the container script. The actual functionality will be placed inside the while
loop.
I've got this script running on my laptop for 7 hours now, and it looks fine, but it doesn't do much. Has anyone else tried this?