Re: [PHP] process creation



2009/1/23 bruce <bedouglas@xxxxxxxxxxxxx>

A simple question (or so I thought).

Does php allow an app to create/start a process/application that can
continue to run on its own, after the initiating program/app terminates?

It appears that the spawning/forking functions might work, but the child
apps would be in a zombie status, and couldn't be killed by an external
program.

Basically, I'd like to create a bunch of test apps/processes, and then to
be
able to kill them by a separate process if the apps take too long to run..

You can have the parent sleep, and then clean up like :

$aPids = array();
for ($i=0;$i<CHILDREN_NUMBER;++$i)
{
if ( $iPid = pcntl_fork() == 0)
{
// children code

exit(0);
}
else
{
// parent code
$aPids[] = $iPid;
}
}

// the parent sleeps
sleep(MAX_EXECUTION_OF_CHILDREN);

for ($i=0;$i<CHILDREN_NUMBER;++$i)
{
// check how the child is doing
$iPid = int *pcntl_waitpid* ( $aChildren[$i], $iStatus , WNOHANG);

if ($iPid == -1)
{
// oh these children ... newer doing what they should
posix_kill($aChildren[$i]);
}

}

this would also take care of zombies.



So.. thoughts/comments would be appreciated!

thanks



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




--
Torok, Alpar Istvan


Relevant Pages

  • Re: [PHP] process creation
    ... Does php allow an app to create/start a process/application that can ... continue to run on its own, after the initiating program/app terminates? ... It appears that the spawning/forking functions might work, ... able to kill them by a separate process if the apps take too long to run.. ...
    (php.general)
  • process creation
    ... Does php allow an app to create/start a process/application that can ... continue to run on its own, after the initiating program/app terminates? ... able to kill them by a separate process if the apps take too long to run.. ...
    (php.general)
  • Re: What Vistas going to look like...
    ... >>> so scripted apps can do more heavyweight stuff. ... OS X ships with PHP. ... (Ruby on Rails, for instance, though this will ...
    (comp.sys.mac.advocacy)
  • Re: VBA to ASP.NET
    ... your web apps like VBA apps, as you will not make the paradigm change ... ..NET in .NET instead of VBA in .NET. ... The basics of programming apply everywhere. ... ASP.NET or PHP? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: running php on an ipod touch
    ... All of the hacks I've seen have focused on user-level apps. ... attempt to even get Apache running on it, much less PHP. ... any webserver (and there are quite a few very small, ... iPod touch -- if you could install anything at all on them. ...
    (uk.comp.sys.mac)