Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13930 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91687 invoked by uid 1010); 23 Nov 2004 06:28:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 91652 invoked from network); 23 Nov 2004 06:28:03 -0000 Received: from unknown (HELO rproxy.gmail.com) (64.233.170.205) by pb1.pair.com with SMTP; 23 Nov 2004 06:28:03 -0000 Received: by rproxy.gmail.com with SMTP id q1so287202rnf for ; Mon, 22 Nov 2004 22:28:03 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=E9BSKFwAskumXznGUrzOpGcCl9A5DJKtmIGGhRY9cEf/DTU2RkfJA4oaQJ6aY12FZKux4ass7AVXWVXzgtZjrmKISh0fWcuT3Y7o7M3ky5XPwjMSec4DCDq+Uns1aIWvEIExVgbISd1YBsEc8A8J/aOgVrCKUBherruk5EJb1fg= Received: by 10.38.77.37 with SMTP id z37mr6619rna; Mon, 22 Nov 2004 22:28:03 -0800 (PST) Received: by 10.38.70.50 with HTTP; Mon, 22 Nov 2004 22:28:03 -0800 (PST) Message-ID: Date: Tue, 23 Nov 2004 08:28:03 +0200 Reply-To: "ilya77@gmail.com" To: Jed Smith Cc: internals@lists.php.net In-Reply-To: <20041123023030.33740.qmail@pb1.pair.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <90e24d4e041122003850705ce8@mail.gmail.com> <20041123023030.33740.qmail@pb1.pair.com> Subject: Re: [PHP-DEV] creating detached processes in PHP From: ilya77@gmail.com ("ilya77@gmail.com") It seems that this discussion is at all obsolete. Cygwin implements fork() by copying the process address space to a new process, and ActivePerl implements fork() using threads. But we are not talking about fork() at all. There is no need for fork() to exist as an API within PHP to implement this SIMPLE, BASIC operation. The bottom line, is that in PHP there is no simple and consistent cross-platform way to create a detached child process. I'm currently implementing a job processing system using PHP 5.0.x, and on my way I've already found a couple of bugs in the engine and fixed one of them. Being a system programmer, this shouldn't be too much of an obstacle for me, but at this moment I'm thinking of the application programmers which don't have an api to create detach processes. That's it... On Mon, 22 Nov 2004 18:30:34 -0800, Jed Smith wrote: > Ilya77@Gmail.Com wrote: > > Unfortunately no. > > On win32 for instance, fork() doesn't exist at all. > > Sure it does, it's just a different model. > > > One of the largest areas of difference is in the process model. UNIX has > fork; Win32 does not. Depending on the use of fork and the code base, > Win32 has two APIs that can be used: CreateProcess and CreateThread. A > UNIX application that forks multiple copies of itself can be reworked in > Win32 to have either multiple processes or a single process with > multiple threads. If multiple processes are used, there are multiple > methods of IPC that can be used to communicate between the processes > (and perhaps to update the code and data of the new process to be like > the parent, if the functionality that fork provides is needed). For more > on IPC, see Interprocess Commuications. > > > fork() doesn't work exactly as planned, i.e.: > > pid2 = fork(); > if(pid2 == 0) { > /* hi, i'm the child */ > > That won't exactly work because Windows requires an exact image to load > from, and it will treat it as if you had just started it (EIP = ENTRY > POINT). However, some uses of fork() revolve around something like this: > > pid2 = fork(); > if(pid2 == 0) { > execve("/bin/part2", ...) > > In this case, great news! It'll work. Use CreateProcess(). > > The assumption that Win32 doesn't have fork() isn't *entirely* correct. > It doesn't have POSIX fork(), but it can do some uses of fork(). > CreateThread() is something else to look into, but if you use fork() for > threading, you're taking the long road. > > >>If I am following you right, wouldn't a fork() followed by an exec > >>(one of the many forms) do what you're needing? > > If it will, CreateProcess() will work, like I said. Look into > http://pecl.php.net/package/ffi as well. You can't pass writable > structures (0.4, WEZ!? :P) but you're bound to be able to whip something > together if you're willing to play dirty. > > Otherwise, just use exec(). :D > > -- > _ > (_)___ Jed Smith, Code Ninja > | / __| RFBs: [email for info] > | \__ \ +1 (541) 606-4145 > _/ |___/ jed@jed.bz (Signed mail preferred: PGP 0x703F9124) > |__/ http://personal.jed.bz/keys/jedsmith.asc > > -- > > > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >