Daemon tool to run PHP script in Linux.

375

Daemon tool to run PHP script in Linux.

Put this in a file (called, say, runphp.sh):      (create this file wherever you want and run it)

vim runphp.sh    (insert following code)

#!/bin/bash
while [ 1 ]; do
sleep 10
php5 ~/script.php
done

save and exit file

OR If you are using thrid party apache server like Xampp…  then

Code:

#!/bin/bash
while [ 1 ]; do
sleep 10
/opt/lampp/bin/php /opt/lampp/htdocs/script.php
done

save and exit
—————————————————————

Then run: Code:
# nohup bash runphp.sh& echo $! >phpid.txt

—————————————————————-

Check error :- cat nohup.out

—————————————————————-

That will just run in the background (even if you close the terminal window), and when you want to close it, just run:

Code:
kill $(<~/phpid.txt)

Explanation of above command : If you want to stop the script then open phpid.txt file find out the Process ID and execute below command

Kill -9 Process ID