On 09/10/2010 11:13 AM, J Ravi Menon wrote:
> Hi,
> I have some basic questions on running php  (5.2.x series on Linux
> 2.6) as a standalone daemon using posix methods (fork() etc..):
> #!/usr/bin/php
> <?php
> require_once ('someclass.php');
> // do some initializations
> .
> // main 'forever' loop - the '$shutdown'  will
> // be set to true via a signal handler
> while(!$shutdown)
> {
>   $a = new SomeClass();
>   $a->doSomething()
> }
> // shutdown logic.
> The 'someclass.php' in turn will include other files (via require_once).
> The above file will be executed directly from the shell. The main loop
> could be listening to new requests via sockets etc..
> Few questions:
> 1) Does opcode cache really matter in such cli-based daemons? As
> 'SomeClass' is instantiated at every loop, I am assuming it is only
> compiled once as it has already been 'seen'.
>     I am not very clear on how apc (or eaccelerator) works in such cases.
> 2) What about garbage collection? In a standard apache-mod-php setup,
> we rely on the end of a request-cycle to free up resources - close
> file descriptiors, free up memory etc..
>     I am assuming in the aforesaid standalone daemon case, we would
> have to do this manually?  In the loop above, would it be better to
> 'unset($a)' explicitly at the end of it before
>     it goes to the next iteration?
> Note: I have written pre-forker deamons in php directly and
> successfully deployed them in the past, but never looked at in depth
> to understand all the nuances. Anecdotally, I have
> done 'unset()' at some critical places were large arrays were used,
> and I think it helped. AFAIK, unlike Java, there is no 'garbage
> collector' thread that does all the magic?
> Thanks,
> Ravi

If I have time when you reply I'll answer the questions, but I must ask:
 Is this purely academic?  Why is this a concern?  Have you encountered
issues?  If so, what?


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to