Linux.com

Home Linux Community Community Blogs General Linux Daemon tool to run PHP script in Linux.

Daemon tool to run PHP script in Linux.

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

 

Comments

Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFD331 Developing Linux Device Drivers
    25 Aug » 29 Aug - Virtual
    Details
  2. LFD411 Embedded Linux Development
    25 Aug » 29 Aug - Santa Clara, CA
    Details
  3. LFS422 High Availability Linux Architecture
    08 Sep » 11 Sep - Raleigh, NC
    Details

View All Upcoming Courses


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board