php-general Digest 24 Jan 2009 08:14:33 -0000 Issue 5919
Topics (messages 287042 through 287061):
Re: Java / PHP Bridge
287042 by: ceo.l-i-e.com
287043 by: Boyd, Todd M.
287044 by: Nathan Rixham
287045 by: ceo.l-i-e.com
287046 by: Nathan Rixham
287051 by: Bastien Koert
287052 by: Boyd, Todd M.
287053 by: Boyd, Todd M.
process creation
287047 by: bruce
287048 by: Alexandre Gaigalas
287049 by: Török Alpár
287050 by: Tony Marston
287054 by: bruce
287055 by: Per Jessen
287056 by: Nathan Rixham
287057 by: Török Alpár
287058 by: Nathan Rixham
287059 by: Török Alpár
287060 by: Ashley Sheridan
Make New-Age Money Online with Google
287061 by: Dora Elless
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Zero real experience, but what I hear is that the Java / PHP bridges are a bit
brittle and difficult to shore up properly...
You may want to consider going with HTTP REST / RPC services instead, as those
are quite solid, and you can get what you want.
Note that this is all hearsay on my part.
ymmv
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Friday, January 23, 2009 9:02 AM
> To: [email protected]
> Subject: Re: [PHP] Java / PHP Bridge
>
>
> Zero real experience, but what I hear is that the Java / PHP bridges
> are a bit brittle and difficult to shore up properly...
>
> You may want to consider going with HTTP REST / RPC services instead,
> as those are quite solid, and you can get what you want.
>
> Note that this is all hearsay on my part.
>
> ymmv
About 3 years ago, I played with an earlier implementation of the
Java-PHP bridge on SourceForge. I could get some rudimentary stuff to
work just fine, but anything complex required a migraine's-worth of
configuration and nit-picky settings on both sides. The technology may
have improved since I played with it last, but I would also recommend
using a web service to accomplish the interoperability.
I'm currently working with a .NET project... I turned the entire thing
into a WCF REST service that will conditionally send SOAP or JSON
replies based on the service client. I can now hook it into Javascript
with a prototype built in jQuery, call it using a PHP SOAP interface,
reference it directly in other ASP.NET projects, and so on and so forth.
You'll get a wealth of benefits aside from making your life easier with
bridging the two languages. :)
HTH,
// Todd
--- End Message ---
--- Begin Message ---
[email protected] wrote:
Zero real experience, but what I hear is that the Java / PHP bridges are a bit
brittle and difficult to shore up properly...
You may want to consider going with HTTP REST / RPC services instead, as those
are quite solid, and you can get what you want.
Note that this is all hearsay on my part.
ymmv
definitely; couldn't agree more; create your java app as a web service
[soap/rpc/rest/xml-rpc] using metro/axis/cxf or suchlike and call it
from php server side to integrate :)
--- End Message ---
--- Begin Message ---
And vice-versa:
Any PHP functionality that needs to be called from Java can be a web service
using whatever weapon you find suitable.
--- End Message ---
--- Begin Message ---
[email protected] wrote:
And vice-versa:
Any PHP functionality that needs to be called from Java can be a web service
using whatever weapon you find suitable.
yup and if I may suggest, wso2 WSF for PHP is probably you're best bet
for doing this;
http://wso2.org/ no finer php web service framework out there
--- End Message ---
--- Begin Message ---
On Fri, Jan 23, 2009 at 10:02 AM, <[email protected]> wrote:
>
> Zero real experience, but what I hear is that the Java / PHP bridges are a
> bit brittle and difficult to shore up properly...
>
> You may want to consider going with HTTP REST / RPC services instead, as
> those are quite solid, and you can get what you want.
>
> Note that this is all hearsay on my part.
>
> ymmv
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Is that hearsay or heresy?
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Bastien Koert [mailto:[email protected]]
> Sent: Friday, January 23, 2009 1:13 PM
> To: [email protected]
> Cc: [email protected]
> Subject: Re: [PHP] Java / PHP Bridge
>
> On Fri, Jan 23, 2009 at 10:02 AM, <[email protected]> wrote:
>
> >
> > Zero real experience, but what I hear is that the Java / PHP bridges
> are a
> > bit brittle and difficult to shore up properly...
> >
> > You may want to consider going with HTTP REST / RPC services
instead,
> as
> > those are quite solid, and you can get what you want.
> >
> > Note that this is all hearsay on my part.
> >
> > ymmv
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> Is that hearsay or heresy?
Heresy is introducing change to a system of belief. Most commonly, you
see it in religious context.
// Todd
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Boyd, Todd M.
> Sent: Friday, January 23, 2009 1:44 PM
> To: 'Bastien Koert'
> Cc: [email protected]
> Subject: RE: [PHP] Java / PHP Bridge
>
> > -----Original Message-----
> > From: Bastien Koert [mailto:[email protected]]
> > Sent: Friday, January 23, 2009 1:13 PM
> > To: [email protected]
> > Cc: [email protected]
> > Subject: Re: [PHP] Java / PHP Bridge
---8<---
> > > Note that this is all hearsay on my part.
---8<---
> > Is that hearsay or heresy?
>
> Heresy is introducing change to a system of belief. Most commonly, you
> see it in religious context.
Grr... I meant to write "system or belief." Since I'm writing another
e-mail, I'll go ahead and add that "hearsay" is more or less, "I heard
it. Now I'm saying it."
// Todd
--- End Message ---
--- Begin Message ---
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..
So.. thoughts/comments would be appreciated!
thanks
--- End Message ---
--- Begin Message ---
On Fri, Jan 23, 2009 at 3:47 PM, bruce <[email protected]> wrote:
> 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..
>
> So.. thoughts/comments would be appreciated!
>
> thanks
>
>
>
Check out the user comments under this function:
http://php.net/ignore_user_abort
--
Alexandre Gomes Gaigalas
[email protected]
http://Alexandre.Gaigalas.Net
--- End Message ---
--- Begin Message ---
2009/1/23 bruce <[email protected]>
> 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
--- End Message ---
--- Begin Message ---
I have achieved this by using curl_exec() to issue another HTTP request on
the same server. By setting the timeout to a small number I regain control
and can continue with other things while the new process runs to completion.
Here is my code:
$url = 'HTTP://' .$_SERVER['HTTP_HOST'] .'/newprocess.php';
// launch this script in another server process, but let it run
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
$content = curl_exec($ch);
if ($content === FALSE) {
$curl_errno = curl_errno($ch);
if ($curl_errno == 28) {
// timeout - ignore
} else {
$curl_error = curl_error($ch);
$errors[] = "CURL error $curl_errno: $curl_error";
} // if
} // if
curl_close($ch);
Hope this helps.
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
""bruce"" <[email protected]> wrote in message
news:[email protected]...
>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..
>
> So.. thoughts/comments would be appreciated!
>
> thanks
>
>
--- End Message ---
--- Begin Message ---
Hi Török.
My test code had/has something similar.. but it kept displaying zombie
processes as well as legitimate processes in the ps tbl/display...
Turns out I had a mistake in the test "client" ap/process that I was
creating... This was causing the child process to die, resulting in a "zombie"
process, until the parent got around to doing a waitpid call...
i think it's ok now...
thanks
ps, torok... are you in the US/Canada? Also, are you up to talking to me about
this project that I'm playing with?
-----Original Message-----
From: Török Alpár [mailto:[email protected]]
Sent: Friday, January 23, 2009 10:09 AM
To: bruce
Cc: [email protected]
Subject: Re: [PHP] process creation
2009/1/23 bruce <[email protected]>
> 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
--- End Message ---
--- Begin Message ---
bruce wrote:
> 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?
Generally yes, but it's partially up to the spawned process to
completely detach itself.
> 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.
I'm not sure, but I think there's something wrong if you can't kill them
with a -9.
> 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..
Why not put a timer in each individual process?
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
bruce wrote:
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.
you keep mentioning this zombie state; make sure that all you're child
processes have an exit(); at the end or at the end of the code where
they are finished; otherwise you get the xombies!
also here is a very simple model you can follow that invariably works
for me:
this will run 10 worker threads:
controller:
<?php
include './your.framework.php';
for($icount=0;$icount<11;$icount++) {
include './worker.php';
}
?>
worker:
<?php
$pid=pcntl_fork();
if(!$pid) {
while(1) {
if($icount) {
$offset = $icount * 50;
} else {
$offset = 0;
}
$db = new mysql_handler( $connection );
$job_list = new job_list;
if( $jobs = $job_list->get($offset) ) {
foreach($jobs as $jdex => $job ) {
//do something with the job
}
} else {
sleep(10);
}
}
} else {
echo "\ndaemon launcher done id $pid\n";
}
?>
the above code is designed to run indefinately in a constant loop which
polls a database for work to do
this is just a very simple example, there are far more complex ways of
doing it, keeping a track of how many processes you have, spawning new
ones when you need them etc etc, but this i find works v well for me,
the key is the $offset; getting jobs from a database and this literally
is the offset used, so if you have say 200 emails to get and each script
processes 50 at a time, only 4 of your threads are working, bump it up
to 10000 and all of them work until the queue drops; the sleep(10) and
the spawn process of about 1 per second ensures that you're polling
every second so jobs are picked up quickly. it's a lot of functionality
for so little code :)
--- End Message ---
--- Begin Message ---
2009/1/23 Nathan Rixham <[email protected]>
> bruce wrote:
>
>> 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.
>>
>>
> you keep mentioning this zombie state; make sure that all you're child
> processes have an exit(); at the end or at the end of the code where they
> are finished; otherwise you get the xombies!
>
> also here is a very simple model you can follow that invariably works for
> me:
>
> this will run 10 worker threads:
>
> controller:
> <?php
> include './your.framework.php';
> for($icount=0;$icount<11;$icount++) {
> include './worker.php';
> }
> ?>
>
> worker:
> <?php
> $pid=pcntl_fork();
> if(!$pid) {
> while(1) {
> if($icount) {
> $offset = $icount * 50;
> } else {
> $offset = 0;
> }
> $db = new mysql_handler( $connection );
> $job_list = new job_list;
> if( $jobs = $job_list->get($offset) ) {
> foreach($jobs as $jdex => $job ) {
> //do something with the job
> }
> } else {
> sleep(10);
> }
> }
> } else {
> echo "\ndaemon launcher done id $pid\n";
> }
> ?>
This would start more than 10 children. Children will continue on with for
loop after they do their work. As you advice that the children have an exit,
i assume that you just overlooked it while writing this example. Also, a
wait on the children, at some point, gets rid of the zombies, as i see from
your code, there is no way you won't have zombie processes, unless the
parent exists, and then the zombies also disappear.
I hope i got it right, it's late here :)
>
> the above code is designed to run indefinately in a constant loop which
> polls a database for work to do
>
> this is just a very simple example, there are far more complex ways of
> doing it, keeping a track of how many processes you have, spawning new ones
> when you need them etc etc, but this i find works v well for me, the key is
> the $offset; getting jobs from a database and this literally is the offset
> used, so if you have say 200 emails to get and each script processes 50 at a
> time, only 4 of your threads are working, bump it up to 10000 and all of
> them work until the queue drops; the sleep(10) and the spawn process of
> about 1 per second ensures that you're polling every second so jobs are
> picked up quickly. it's a lot of functionality for so little code :)
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Torok, Alpar Istvan
--- End Message ---
--- Begin Message ---
Török Alpár wrote:
2009/1/23 Nathan Rixham <[email protected]>
bruce wrote:
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.
you keep mentioning this zombie state; make sure that all you're child
processes have an exit(); at the end or at the end of the code where they
are finished; otherwise you get the xombies!
also here is a very simple model you can follow that invariably works for
me:
this will run 10 worker threads:
controller:
<?php
include './your.framework.php';
for($icount=0;$icount<11;$icount++) {
include './worker.php';
}
?>
worker:
<?php
$pid=pcntl_fork();
if(!$pid) {
while(1) {
if($icount) {
$offset = $icount * 50;
} else {
$offset = 0;
}
$db = new mysql_handler( $connection );
$job_list = new job_list;
if( $jobs = $job_list->get($offset) ) {
foreach($jobs as $jdex => $job ) {
//do something with the job
}
} else {
sleep(10);
}
}
} else {
echo "\ndaemon launcher done id $pid\n";
}
?>
This would start more than 10 children. Children will continue on with for
loop after they do their work. As you advice that the children have an exit,
i assume that you just overlooked it while writing this example. Also, a
wait on the children, at some point, gets rid of the zombies, as i see from
your code, there is no way you won't have zombie processes, unless the
parent exists, and then the zombies also disappear.
I hope i got it right, it's late here :)
lol the script will only run 10 children, and as mentioned directly
below, it is designed to run forever - the example doesn't fit the exact
needs, but following bruces earlier posts this may be a model he can
follow. I'm aware it could be fleshed out with much more code and error
handling, but it's just a little model to get one started :)
regards torak and hope you're well!
the above code is designed to run indefinately in a constant loop which
polls a database for work to do
this is just a very simple example, there are far more complex ways of
doing it, keeping a track of how many processes you have, spawning new ones
when you need them etc etc, but this i find works v well for me, the key is
the $offset; getting jobs from a database and this literally is the offset
used, so if you have say 200 emails to get and each script processes 50 at a
time, only 4 of your threads are working, bump it up to 10000 and all of
them work until the queue drops; the sleep(10) and the spawn process of
about 1 per second ensures that you're polling every second so jobs are
picked up quickly. it's a lot of functionality for so little code :)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
as i said it's hate here, and i might be wrong but consider the following :
for($icount=0;$icount<11;$icount++)
{
$iPid = pcntl_fork();
$iChildrenCount = 0;
if ($iPid == 0)
{
// child
echo ("child $icount\n");
}
else
{
// parrent
}
}
this is essential what you do in your example? If so, this code does not
start 10 children. It starts more.
2009/1/23 Nathan Rixham <[email protected]>
> Török Alpár wrote:
>
>> 2009/1/23 Nathan Rixham <[email protected]>
>>
>> bruce wrote:
>>>
>>> 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.
>>>>
>>>>
>>>> you keep mentioning this zombie state; make sure that all you're child
>>> processes have an exit(); at the end or at the end of the code where they
>>> are finished; otherwise you get the xombies!
>>>
>>> also here is a very simple model you can follow that invariably works for
>>> me:
>>>
>>> this will run 10 worker threads:
>>>
>>> controller:
>>> <?php
>>> include './your.framework.php';
>>> for($icount=0;$icount<11;$icount++) {
>>> include './worker.php';
>>> }
>>> ?>
>>>
>>> worker:
>>> <?php
>>> $pid=pcntl_fork();
>>> if(!$pid) {
>>> while(1) {
>>> if($icount) {
>>> $offset = $icount * 50;
>>> } else {
>>> $offset = 0;
>>> }
>>> $db = new mysql_handler( $connection );
>>> $job_list = new job_list;
>>> if( $jobs = $job_list->get($offset) ) {
>>> foreach($jobs as $jdex => $job ) {
>>> //do something with the job
>>> }
>>> } else {
>>> sleep(10);
>>> }
>>> }
>>> } else {
>>> echo "\ndaemon launcher done id $pid\n";
>>> }
>>> ?>
>>>
>>
>> This would start more than 10 children. Children will continue on with for
>> loop after they do their work. As you advice that the children have an
>> exit,
>> i assume that you just overlooked it while writing this example. Also, a
>> wait on the children, at some point, gets rid of the zombies, as i see
>> from
>> your code, there is no way you won't have zombie processes, unless the
>> parent exists, and then the zombies also disappear.
>>
>> I hope i got it right, it's late here :)
>>
>>
>>
> lol the script will only run 10 children, and as mentioned directly below,
> it is designed to run forever - the example doesn't fit the exact needs, but
> following bruces earlier posts this may be a model he can follow. I'm aware
> it could be fleshed out with much more code and error handling, but it's
> just a little model to get one started :)
>
> regards torak and hope you're well!
>
>
> the above code is designed to run indefinately in a constant loop which
>>> polls a database for work to do
>>>
>>> this is just a very simple example, there are far more complex ways of
>>> doing it, keeping a track of how many processes you have, spawning new
>>> ones
>>> when you need them etc etc, but this i find works v well for me, the key
>>> is
>>> the $offset; getting jobs from a database and this literally is the
>>> offset
>>> used, so if you have say 200 emails to get and each script processes 50
>>> at a
>>> time, only 4 of your threads are working, bump it up to 10000 and all of
>>> them work until the queue drops; the sleep(10) and the spawn process of
>>> about 1 per second ensures that you're polling every second so jobs are
>>> picked up quickly. it's a lot of functionality for so little code :)
>>>
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>>
>>
>>
>
--
Torok, Alpar Istvan
--- End Message ---
--- Begin Message ---
On Sat, 2009-01-24 at 00:22 +0200, Török Alpár wrote:
> as i said it's hate here, and i might be wrong but consider the following :
>
> for($icount=0;$icount<11;$icount++)
> {
> $iPid = pcntl_fork();
> $iChildrenCount = 0;
> if ($iPid == 0)
> {
> // child
> echo ("child $icount\n");
> }
> else
> {
> // parrent
> }
> }
>
> this is essential what you do in your example? If so, this code does not
> start 10 children. It starts more.
>
> 2009/1/23 Nathan Rixham <[email protected]>
>
> > Török Alpár wrote:
> >
> >> 2009/1/23 Nathan Rixham <[email protected]>
> >>
> >> bruce wrote:
> >>>
> >>> 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.
> >>>>
> >>>>
> >>>> you keep mentioning this zombie state; make sure that all you're child
> >>> processes have an exit(); at the end or at the end of the code where they
> >>> are finished; otherwise you get the xombies!
> >>>
> >>> also here is a very simple model you can follow that invariably works for
> >>> me:
> >>>
> >>> this will run 10 worker threads:
> >>>
> >>> controller:
> >>> <?php
> >>> include './your.framework.php';
> >>> for($icount=0;$icount<11;$icount++) {
> >>> include './worker.php';
> >>> }
> >>> ?>
> >>>
> >>> worker:
> >>> <?php
> >>> $pid=pcntl_fork();
> >>> if(!$pid) {
> >>> while(1) {
> >>> if($icount) {
> >>> $offset = $icount * 50;
> >>> } else {
> >>> $offset = 0;
> >>> }
> >>> $db = new mysql_handler( $connection );
> >>> $job_list = new job_list;
> >>> if( $jobs = $job_list->get($offset) ) {
> >>> foreach($jobs as $jdex => $job ) {
> >>> //do something with the job
> >>> }
> >>> } else {
> >>> sleep(10);
> >>> }
> >>> }
> >>> } else {
> >>> echo "\ndaemon launcher done id $pid\n";
> >>> }
> >>> ?>
> >>>
> >>
> >> This would start more than 10 children. Children will continue on with for
> >> loop after they do their work. As you advice that the children have an
> >> exit,
> >> i assume that you just overlooked it while writing this example. Also, a
> >> wait on the children, at some point, gets rid of the zombies, as i see
> >> from
> >> your code, there is no way you won't have zombie processes, unless the
> >> parent exists, and then the zombies also disappear.
> >>
> >> I hope i got it right, it's late here :)
> >>
> >>
> >>
> > lol the script will only run 10 children, and as mentioned directly below,
> > it is designed to run forever - the example doesn't fit the exact needs, but
> > following bruces earlier posts this may be a model he can follow. I'm aware
> > it could be fleshed out with much more code and error handling, but it's
> > just a little model to get one started :)
> >
> > regards torak and hope you're well!
> >
> >
> > the above code is designed to run indefinately in a constant loop which
> >>> polls a database for work to do
> >>>
> >>> this is just a very simple example, there are far more complex ways of
> >>> doing it, keeping a track of how many processes you have, spawning new
> >>> ones
> >>> when you need them etc etc, but this i find works v well for me, the key
> >>> is
> >>> the $offset; getting jobs from a database and this literally is the
> >>> offset
> >>> used, so if you have say 200 emails to get and each script processes 50
> >>> at a
> >>> time, only 4 of your threads are working, bump it up to 10000 and all of
> >>> them work until the queue drops; the sleep(10) and the spawn process of
> >>> about 1 per second ensures that you're polling every second so jobs are
> >>> picked up quickly. it's a lot of functionality for so little code :)
> >>>
> >>>
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>>
> >>>
> >>
> >>
> >
>
>
I think possibly you want to execute a new script of non-PHP origin? In
which case, using exec() and calling a script with an & (meaning to run
in the background) and passing output to /dev/null should do the trick.
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Hi!
Do you Know That Much Money is Being Spent Online Nowadays? Now is the Right
Time to Get a Piece of It!
Are you wondering how people make money through the Internet by doing almost
nothing? At first, I was wary about working from home, because I had heard
horror stories about the Internet. But I'd heard that there were rounds of
layoffs coming at my company, so I figured I should do something to try and
have a backup should the worst happen.
I was amazed when I got this Free-Trial Kit. It started working right away. By
the time the layoffs happened, I was already making more money from Google than
I was in my job. Now I use Google full time and have a great income.
Unfortunately, I cannot send this offer to everyone to prevent the value and
potency of this information from being "watered down". That's why I am sending
this email only to people I know and care about. A friend of mine gave me your
email address, that's why I decided to send that offer to you too(I am sorry if
I disturbed you in anyway).
If you are interested to participate in this program, send an answer to
[email protected], saying that you want to join too, so you can
receive your Risk-Free Kit and start enjoying a life free from money worries
for the rest of your life!
Regards,
a trusted Friend
--- End Message ---