Take the 2-minute tour ×

While the idea of a PHP daemon has been covered to death on here, I haven't found anything specifically related to how to do this in PHP 5.3. As I've been told, 5.3 introduced new garbage collection/memory management to allow PHP to more cleanly run as a daemon.

I know PHP's no one's first choice for this kind of thing, but in my circumstances it might have to do.

I know in PHP 4, you would have to use something like the System_Daemon class, but I was wondering if that was still needed with the new version of PHP, and wether I'd need to do anything special to use the new features.

share|improve this question
look into node.js for daemons. much better for this sort of thing, and it's javascript so it shoudn't be hard to pick up. –  dqhendricks Aug 30 '11 at 18:13
@dqhendricks interesting option, thanks, I'll look into that –  MT. Aug 30 '11 at 18:18
add comment

2 Answers

up vote 3 down vote accepted

PHP uses reference counting for managing allocated memory. When a cycle exists between objects, their reference count is never decremented and the objects are never freed (until the end of the script).

The only goal of the garbage collector added in PHP5.3 is to kill those cycles. This effectively helps in reducing the memory usage of long running scripts, like daemons.

Other than that, PHP5.3 adds nothing new for long running scripts / daemons.

There has been some efforts in making app servers in PHP lately, you may want to look at them:


share|improve this answer
add comment

The garbage collector is an internal thing. It does not change how you write a daemon. And there was just a more inefficient form of garbage collection (resource freeing) before PHP 5.3, that's all. http://php.net/manual/en/features.gc.performance-considerations.php

You are supposed to still fork daemon processes, as there is no threading support to use instead. And this implicitly takes care of freeing memory, so it doesn't practically matter.

share|improve this answer
add comment

Your Answer


