sniko Posted September 7, 2012 Share Posted September 7, 2012 My sight of php stopped when it reached the internet, aka, the first stop, but I've come across this article which allows you to create daemons using php. What is a daemon? A background process that handles requests for services such as print spooling and is dormant when not required. Link to Article I thought it was an interesting read! What are your thoughts? Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted September 8, 2012 Share Posted September 8, 2012 Demons are basically console applications which are started in the init.d (some sort of... special linux service which starts software on boot). Now, making demons in PHP can be useful, and I did some myself too. All depends what you actually need. Quote Link to comment Share on other sites More sharing options...
Dave Posted September 8, 2012 Share Posted September 8, 2012 I'm currently experimenting with a mail server which is a very simple PHP daemon. Due to my projects needs using a complete mail server would be very un-efficient. They can be very useful if used correctly. Nice little find. Quote Link to comment Share on other sites More sharing options...
Spudinski Posted September 9, 2012 Share Posted September 9, 2012 Demons are basically console applications which are started in the init.d (some sort of... special linux service which starts software on boot). On a Unix-like system, the common method for a process to become a daemon, when the process is started from the command line or from a startup script such as an rc file or a SystemStarter script, involves: Dissociating from the controlling tty Becoming a session leader Becoming a process group leader Executing as a background task by forking and exiting (once or twice). This is required sometimes for the process to become a session leader. It also allows the parent process to continue its normal executions Source: http://en.wikipedia.org/wiki/Daemon_(computing) /end Anyway, PHP isn't the best tool to use for creating deamons. They work, and they do it quite "ok" actually, but unless your app is written in PHP and there will be conflicts using other languages you're better off using something else. I would suggest the following in order of how my personal opinion drifts: Python, 'nuff said. C, again, Linux is built on Python and C. Node, makes other sysmins cry when they see JavaScript server-side, but it works damn well(although I wouldn't suggest using it if you ever need to scale). Bash, although also not technically a programming language since it has no language constructs - it does do system administration tasks very fast. PHP.. But, I think it's important to discuss the reasons why one would *want* to run something as a daemon. Event-driven applications such as cron(tab) is a great example for why you would want it to run as a daemon. Speaking specifically PHP, an event processor for an application would make a good daemon. For those of you who doesn't know, an event-processor is something like a "shopping cart" - when you press checkout and the order is processed, certain things need to take place: such as packaging the contents, wrapping it up, and sending it off via post. Each event is processed individually, yet they all need to happen in a specific order. So without an event processor, it would be like saying the package has been posted, without a wrapped package - which is rather illogical and would break minds(in this case, computer applications). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.