I am trying to run the php script (below) named daemon.php as a back ground process using unix.
#!/usr/bin/php
<?php
$count = 0;
while(true){
$count = $count + 1;
file_put_contents('daemon1.log', $count, FILE_APPEND);
sleep(1);
}
?>
If I run it in the foreground using the command below
php daemon.php
The file deamon1.log starts getting written to. Also if I enter the command:
ps | grep php
I get the out put
10573 ttys000 0:00.20 php daemon.php
If I try to run it as a background process using the command
php daemon.php &
I get the console out put
[1] 10584
And the command
ps | grep php
Returns
10584 ttys000 0:00.02 php daemon.php
But nothing is written to deamon1.log. Can anyone tell me what I'm doing wrong?