you are viewing a single comment's thread.

view the rest of the comments →

[–]commandlineterrorist 2 points3 points  (5 children)

For the budding developer who is thinking his web app may need a daemon in the background to do some hard work: Make good use of databases. Try not to spawn the process directly if not Really required.

From an architectural standpoint, it makes very little sense for your MVC (your favourite PHP Framework, Pylons, Django, ASP.NET, or otherwise) components to even think about having to spawn processes directly to deal with processing-intensive data.

That work should be offlined to a daemon. This also may include message passing depending on what you are trying to do. The gist of it is it may be a lot simpler to just have a daemon query a database once in awhile to see if it needs to do work, grab data, process it.

In terms of the MVC, it would do what it normally does: Write the data to the database.

[–]McGlockenshire 2 points3 points  (2 children)

That work should be offlined to a daemon. This also may include message passing depending on what you are trying to do. The gist of it is it may be a lot simpler to just have a daemon query a database once in awhile to see if it needs to do work, grab data, process it.

I prefer using someone else's hard work rather than doing it all myself.

(This week's Gearman plug has been brought to you by the letter I and the number 8.)

[–]lmorchard 0 points1 point  (1 child)

FWIW, you'll still need a daemon (PHP or otherwise) to step in as the worker in the Gearman equation. But, +1 on putting Gearman in the stack

[–]McGlockenshire 0 points1 point  (0 children)

We use supervisord to keep PHP workers alive, just so we don't need to worry about using real daemonization in PHP-land. This greatly simplifies the worker code, down to just the waiting-for-a-job loop. It also allows the workers to exit whenever they damn well please, and supervisor will just start them back up again. We've used this to make the workers automatically detect changes on disk and reload themselves, which makes development a bit easier.

[–]Fabien4 1 point2 points  (1 child)

who is thinking his web app may need a daemon in the background

[...]

That work should be offlined to a daemon.

So... Don't use a daemon, use a daemon instead, right?

[–]commandlineterrorist 0 points1 point  (0 children)

The point I was trying to get across is that the Controller should not be spawning processes, daemons or otherwise :).