Re: [PHP] Re: process creation
Per Jessen wrote: 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;$icount11;$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. Thats right - with the code above, each new child will continue creating more processes. To get exactly 10 children running the same code: if ($iPid == 0) { // child echo (child $icount\n); // do childish stuff // then exit exit; } /Per Jessen, Zürich for($icount=0;$icount11;$icount++) Iterates 10 times?? Hmm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: process creation
Tom Sinclair wrote: Per Jessen wrote: for($icount=0;$icount11;$icount++) Iterates 10 times?? Hmm 10, 11 - no big difference is there? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: process creation
Hmm, are people getting confused between and = ? for($icount=0;$icount11;$icount++) (is less than 11) for($icount=0;$icount=10;$icount++) (is less than or equal to 10) Both iterate 10 times. Michael Kubler *G*rey *P*hoenix *P*roductions http://www.greyphoenix.biz Per Jessen wrote: Tom Sinclair wrote: Per Jessen wrote: for($icount=0;$icount11;$icount++) Iterates 10 times?? Hmm 10, 11 - no big difference is there? /Per Jessen, Zürich
Re: [PHP] Re: process creation
On Mon, 2009-01-26 at 00:42 +1030, Michael Kubler wrote: Hmm, are people getting confused between and = ? for($icount=0;$icount11;$icount++) (is less than 11) for($icount=0;$icount=10;$icount++) (is less than or equal to 10) Both iterate 10 times. Michael Kubler *G*rey *P*hoenix *P*roductions http://www.greyphoenix.biz Per Jessen wrote: Tom Sinclair wrote: Per Jessen wrote: for($icount=0;$icount11;$icount++) Iterates 10 times?? Hmm 10, 11 - no big difference is there? /Per Jessen, Zürich No, both iterate 11 times, because you start at 0. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: process creation
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;$icount11;$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. Thats right - with the code above, each new child will continue creating more processes. To get exactly 10 children running the same code: if ($iPid == 0) { // child echo (child $icount\n); // do childish stuff // then exit exit; } /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: process creation
2009/1/23 Nathan Rixham nrix...@gmail.com 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;$icount11;$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 1 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
Re: [PHP] Re: process creation
Török Alpár wrote: 2009/1/23 Nathan Rixham nrix...@gmail.com 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;$icount11;$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 1 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: process creation
as i said it's hate here, and i might be wrong but consider the following : for($icount=0;$icount11;$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 nrix...@gmail.com Török Alpár wrote: 2009/1/23 Nathan Rixham nrix...@gmail.com 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;$icount11;$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 1 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
Re: [PHP] Re: process creation
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;$icount11;$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 nrix...@gmail.com Török Alpár wrote: 2009/1/23 Nathan Rixham nrix...@gmail.com 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;$icount11;$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 1 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php