This article will show how to create a simple, fast and efficient php daemon for linux. It's done thanks to the easy_php_daemon php calss that I have wrote myself.
Easy steps to create the daemon:
#Firstly, copy the template file for managing your daemon
user@yourhost:~# cp /etc/init.d/skeleton /etc/init.d/your_daemon
#Make your daemon exacutable
user@yourhost:~# chmod +x /etc/init.d/your_daemon
user@yourhost:~# chmod +x /your_daemon_path
#Edit the following linies
user@yourhost:~# nano /etc/init.d/your_daemon
##################################################
DESC="your description"
NAME="your daemon name" # it shall be less then 15 characters.
DAEMON="your php daemon path" #example: /home/your_daemon.php
PIDFILE="path to your pid file" #file that will contain your process id.
#change the verbose settings /lib/init/vars.sh
user@yourhost:~# nano /lib/init/vars.sh
VERBOSE=yes
#Add the daemon to autostart
user@yourhost:~# update-rc.d your_daemon default
#Download easy_php_daemon
user@yourhost:~# git clone https://github.com/indigo7333/easy_php_daemon.git
#create your daemon file
user@yourhost:~# nano /your_daemon.php
#!/usr/bin/php -qEasy steps to create the daemon:
#Firstly, copy the template file for managing your daemon
user@yourhost:~# cp /etc/init.d/skeleton /etc/init.d/your_daemon
#Make your daemon exacutable
user@yourhost:~# chmod +x /etc/init.d/your_daemon
user@yourhost:~# chmod +x /your_daemon_path
#Edit the following linies
user@yourhost:~# nano /etc/init.d/your_daemon
##################################################
DESC="your description"
NAME="your daemon name" # it shall be less then 15 characters.
DAEMON="your php daemon path" #example: /home/your_daemon.php
PIDFILE="path to your pid file" #file that will contain your process id.
#change the verbose settings /lib/init/vars.sh
user@yourhost:~# nano /lib/init/vars.sh
VERBOSE=yes
#Add the daemon to autostart
user@yourhost:~# update-rc.d your_daemon default
#Download easy_php_daemon
user@yourhost:~# git clone https://github.com/indigo7333/easy_php_daemon.git
#create your daemon file
user@yourhost:~# nano /your_daemon.php
<?php
require_once("easy_php_daemon/indigo_daemon.class.php");
class yourclass extends indigo_daemon
{
public function start_process()
{
//your daemon work
return 1;
}
public function include_libraries()
{
//include some libraries
}
}
$daemon=new yourclass();
$daemon->log_file='/path/to/log_file'; //Path to Log file
$daemon->pid_file='/path/to/pid_file'; //Path to PidFile
$daemon->daemon_name='Your Daemon Name'; //Your Daemon Name
$daemon->init();
$daemon->write_log_file("test"); //write something to log file
$daemon->include_libraries();
$daemon->infinite(1000000); //execute the process every second
$daemon->shutdown();
That's all to create a simple and easy php daemon for debian wheezy linux.
Комментариев нет:
Отправить комментарий