truetobetrue
truetobetrue

Reputation: 13

Launch simple php daemon on Ubuntu

I want launch simple php daemon on Ubuntu without fork.

source f.php:

#!/usr/bin/php
<?php
file_put_contents('/var/www/3.txt',date("H:i:s", time()) . "\n", FILE_APPEND);
while (true) {
    file_put_contents('/var/www/3.txt',date("H:i:s", time()) . "\n", FILE_APPEND);
    sleep(1);
}

launch:

root@ubuntu:/var/www# ./f.php &
[3] 10323

On FreeBSD this work well on Ubuntu file 3.txt is not updating :( permissions are ok (777)

Upvotes: 1

Views: 610

Answers (1)

Saket Patel
Saket Patel

Reputation: 6683

can you check that the path you are pointing to for the binary file of PHP is correct, i mean PHP is really installed in /usr/bin/php, you can check that by using below command

which php

also you can try to run it manually instead of running it as an executable by below command

php -f f.php &

and also check if your php file is giving any errors in apache logs, you can find apache logs in /var/log/apache2/error.log

and also make sure that php5-cli package is installed by executing following command

apt-get install php5-cli

Update:

according to http://www.freelance-it-consultant.com/blog/php-cli-script-running-background-ubuntu, there is some bug in ubuntu when php is run through CLI it expects some input from user, so can you try this method if that works for you?

php -q f.php < /dev/null &

Upvotes: 1

Related Questions