Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
Site Navigation
Linux Forums
Linux Articles
Product Showcase
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Free Publications


In Unix and other computer multitasking operating systems, a daemon is a computer program that runs in the background, rather than under the direct control of a user; they are usually initiated as background processes. Typically daemons have names that end with the letter "d": for example, syslogd, the daemon that handles the system log, or sshd, which handles incoming SSH connections. In a Unix environment, the parent process of a daemon is often (but not always) the init process (PID=1). Processes usually become daemons by forking a child process and then having their parent process immediately exit, thus causing init to adopt the child process. This is a somewhat simplified view of the process as other operations are generally performed, such as dissociating the daemon process from any controlling tty. Convenience routines such as daemon(3) exist in some UNIX systems for that purpose.

PostHeaderIcon

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




Rate This Article: poorexcellent
 
Comments about this article

Comment title: * please do not put your response text here