NYCPHP Meetup

NYPHP.org

[nycphp-talk] fork (broadcast emailer: is this sane strategy)

ophir prusak lists at prusak.com
Wed Aug 18 08:20:58 EDT 2004


I've never had to use real forks in PHP thought I have in Perl.
Using the PHP exec command doesn't do "real" forking, it just creates a 
new process in the background.
If you want real forking use the pcntl_fork command.
http://us3.php.net/manual/en/function.pcntl-fork.php
The user comments are helpful

Ophir

David Mintz wrote:

>I'm a total forkin' newbie, but I've read that with "real" forking, the OS
>will make two identical copies of address spaces, one for the parent and
>the other for the child. If parent has set $foo = 7 prior to the fork, the
>child would see $foo = 7 as well.  Whereas in this example, we're just
>launching another independent instance of ourself, and as such we start
>with a clean slate.
>
>True?
>
>On Tue, 17 Aug 2004 drydell at att.net wrote:
>
>  
>
>>I'm not sure if it is or not, but it behaves in exactly the same way... I have several long running tasks that I can initiate from a web page, have the next page rendered in the browser immediately, and then watch the background tasks run from a UNIX shell...
>>
>>    
>>
>>>Just as an aside, it's possible to fork a detached php process, all you need
>>>      
>>>
>>to do is turn off stdin and stdout (and you should trap output/errors to a log):
>>    
>>
>>>exec("/path/to/php /your/script.php 2>>/your/logfile.log >&- <&-
>>>      
>>>
>>>>/your/logfile.log");
>>>>        
>>>>
>>That's what I'm doing (I think). Although -- correct me if I'm wrong -- I
>>believe technically that ain't true forking, as in pcntl_fork().
>>    
>>
>
>
>
>---
>David Mintz
>http://davidmintz.org/
>
>        "Anybody else got a problem with Webistics?" -- Sopranos 24:17
>_______________________________________________
>New York PHP Talk
>Supporting AMP Technology (Apache/MySQL/PHP)
>http://lists.nyphp.org/mailman/listinfo/talk
>http://www.newyorkphp.org
>  
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20040818/d80d08fd/attachment.html>


More information about the talk mailing list