I need to run a php script as daemon process (wait for instructions and do stuff). cron job will not do it for me because actions need to be taken as soon as instruction arr
Extending Emil Ivaov answer, You can do the following to close STDIN, STDOUT AND STDERROR in php
if (!fclose(STDIN)) {
exit("Could not close STDIN");
}
if (!fclose(STDOUT)) {
exit("Could not close STDOUT");
}
if (!fclose(STDERR)) {
exit("Could not close STDERR");
}
$STDIN = fopen('/dev/null', 'r');
$STDOUT = fopen('/dev/null', 'w');
$STDERR = fopen('/var/log/our_error.log', 'wb');
Basically you close the standard streams so that PHP has no place to write. The following fopen calls will set the standard IO to /dev/null.
I have read this from book of Rob Aley - PHP beyond the web