Jump to content
MakeWebGames

Creating daemons using PHP


sniko

Recommended Posts

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?

Link to comment
Share on other sites

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:

  1. Python, 'nuff said.
  2. C, again, Linux is built on Python and C.
  3. 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).
  4. Bash, although also not technically a programming language since it has no language constructs - it does do system administration tasks very fast.
  5. 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).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...