I will be writing my first daemon in php and I have a couple really basic questions that I need help with.
What packages need to be installed on my linux server and Does anything in PHP need to be enabled? So far I have gotten this - http://pear.php.net/package/System_Daemon/download
Where on server do I save my daemon files?
I have a number of files that need to be included within the daemon that contain classes and functions for gathering emails and attachments through IMAP. All of these files are currently in my web public directory, how do I include these files within my daemon?
I think that is everything I need to get started. Thanks so much!
To create demons in PHP you need to use the extensions pcntl and posix. To implement the fast communication withing daemon scripts it is recommended to use the extension libevent for asynchronous I/O.
A daemon is a Linux program that run in the background, just like a 'Service' on Windows. It can perform all sorts of tasks that do not require direct user input. Apache is a daemon, so is MySQL. All you ever hear from them is found in somewhere in /var/log , yet they silently power over 40% of the Internet.
You can put a task (such as command or script) in a background by appending a & at the end of the command line. The & operator puts command in the background and free up your terminal. The command which runs in background is called a job. You can type other command while background command is running.
- What packages need to be installed on my linux server and Does anything in PHP need to be enabled? So far I have gotten this - http://pear.php.net/package/System_Daemon/download
As long your php installation includes sockets you'll be able to write any daemon. Most of current php packages provides sockets support. You need a shell access to be able to configure and execute your daemon, it won't be done by serving it as a web application.
I don't know about the package you mentioned but it's likely to be a way to make you easier to write and maintain your daemon.
- Where on server do I save my daemon files?
Anywhere, you just need a shell access, you'll probably need root privileges, if you need to launch it on a port under 1024. Create a special user, eventualy make a jail, you'll probably be fine.
- I have a number of files that need to be included within the daemon that contain classes and functions for gathering emails and attachments through IMAP. All of these files are currently in my web public directory, how do I include these files within my daemon?
Use a config file, such as a ini which is supported by PHP to specify a data directory and read from.
Further reading :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With