php-general Digest 23 Jan 2009 14:30:27 -0000 Issue 5918
php-general Digest 23 Jan 2009 14:30:27 - Issue 5918 Topics (messages 287037 through 287041): Re: To check for existing user in database 287037 by: Lars Torben Wilson Java / PHP Bridge 287038 by: DaveLyons85 Re: distinguish between null variable and unset variable 287039 by: Thodoris Re: PHP 5.2.8 fails to find libiconv 287040 by: Thodoris Authentication by client certificate 287041 by: Jesus Campos Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- 2009/1/16 Shawn McKenzie nos...@mckenzies.net: Lars Torben Wilson wrote: 2009/1/15 tedd tedd.sperl...@gmail.com: At 9:46 AM -0800 1/15/09, Chris Carter wrote: Chris: That's not the way I would do it. After establishing a connection with the database, I would use the query: $query SELECT email FROM owners WHERE email = '$emailAddress' : $result = mysql_query($query) or die(mysql_error()); if(mysql_affected_rows()) { // then report a duplicate email/record. } else { // else insert a new record in the dB. } HTH's tedd You want to use mysql_num_rows() there instead of mysql_affected_rows(). (Just a typo in this case, I suspect, but for the benefit of the less experienced it's worth pointing out.) For the newer PHP users, mysql_num_rows() tells you the number of rows you found with a SELECT query, while mysql_affected_rows() tells you how many rows you affected with an INSERT, UPDATE, REPLACE INTO, or DELETE query. Regards, Torben mysql_num_rows() may make more sense, however mysql_affected_rows() will work the same with a select. The PHP mysql_affected_rows() calls the MySQL mysql_affected_rows(), which states: For SELECT statements, mysql_affected_rows() works like mysql_num_rows(). (My apologies for not following the thread for a week. . .) Yes, you are right, except that the restriction isn't with MySQL, it's within PHP. The problem is that if you leave out the optional resource argument it works like you describe, but if you include the argument, PHP barfs. It's good practice to use the one intended for the purpose at hand, even if the other will work in some (or even most) situations. I suppose this is a bug in PHP in that it should really behave the way that the MySQL API does to avoid surprises, but it does illustrate the point that using the intended function is easier in the long run: you know it's been tested against its intended usage and not necessarily against others. Regards, Torben ---End Message--- ---BeginMessage--- Hi all, I've been looking into running a complex Java simulation I've made from a LAMP web server and was wondering if this was possible? Basically the user is able to set the configuation from a page and then my intention is for a PHP script to execute the Java. I've read into all the Java/PHP bridge sf stuff (without actually attempting to do it yet admitidly), but was wondering if something like this is possible, there will be several PHP objects that I'll need to be passed over to instantiate my Java simulation class. Any info is much appreciated Thanks DL -- View this message in context: http://www.nabble.com/Java---PHP-Bridge-tp21620091p21620091.html Sent from the PHP - General mailing list archive at Nabble.com. ---End Message--- ---BeginMessage--- How can I tell the difference between a variable whose value is null and a variable which is not set? // cannot use === null: ket% php -r '$null = null; var_dump(null === $null);' bool(true) ket% php -r 'var_dump(null === $unset);' bool(true) ket% // - cannot use isset() either: ket% php -r '$null = null; var_dump(isset($null));' bool(false) ket% php -r 'var_dump(isset($unset));' bool(false) ket% Although this is a good problem to lose time for I think it is pointless. Since assigning the null constant to a var is making PHP to pretend like it never existed. Is this not the point? Without this feature I can think many cases that isset or is_null would be useless. You could always assign to something the empty string '' and use empty() to check it as an alternative. BTW what are you trying to do? -- Thodoris ---End Message--- ---BeginMessage--- Hi, I'm attempting to install PHP 5.2.8 on CentOS 5.2 x86_64. The glibc iconv doesn't seem to function very well, leading to a bunch of failed tests when running 'make test' (see below). After a bit of Googling I stumbled upon http://nl2.php.net/manual/en/intro.iconv.php which suggests to install libiconv instead of relying on glibc's iconv, when things go wrong. My configure line reads as follows: ./configure --prefix=/chroot/apache2/php
[PHP] Java / PHP Bridge
Hi all, I've been looking into running a complex Java simulation I've made from a LAMP web server and was wondering if this was possible? Basically the user is able to set the configuation from a page and then my intention is for a PHP script to execute the Java. I've read into all the Java/PHP bridge sf stuff (without actually attempting to do it yet admitidly), but was wondering if something like this is possible, there will be several PHP objects that I'll need to be passed over to instantiate my Java simulation class. Any info is much appreciated Thanks DL -- View this message in context: http://www.nabble.com/Java---PHP-Bridge-tp21620091p21620091.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] distinguish between null variable and unset variable
How can I tell the difference between a variable whose value is null and a variable which is not set? // cannot use === null: ket% php -r '$null = null; var_dump(null === $null);' bool(true) ket% php -r 'var_dump(null === $unset);' bool(true) ket% // - cannot use isset() either: ket% php -r '$null = null; var_dump(isset($null));' bool(false) ket% php -r 'var_dump(isset($unset));' bool(false) ket% Although this is a good problem to lose time for I think it is pointless. Since assigning the null constant to a var is making PHP to pretend like it never existed. Is this not the point? Without this feature I can think many cases that isset or is_null would be useless. You could always assign to something the empty string '' and use empty() to check it as an alternative. BTW what are you trying to do? -- Thodoris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 5.2.8 fails to find libiconv
Hi, I'm attempting to install PHP 5.2.8 on CentOS 5.2 x86_64. The glibc iconv doesn't seem to function very well, leading to a bunch of failed tests when running 'make test' (see below). After a bit of Googling I stumbled upon http://nl2.php.net/manual/en/intro.iconv.php which suggests to install libiconv instead of relying on glibc's iconv, when things go wrong. My configure line reads as follows: ./configure --prefix=/chroot/apache2/php --with-apxs2=/chroot/apache2/bin/apxs --disable-cgi --with-zlib --with-gettext --enable-sockets --with-xmlrpc --with-xsl --with-config-file-path=/php/etc --with-mcrypt --enable-mbregex --with-gd --with-mime-magic=/usr/share/mime/magic --enable-mbstring=all --with-openssl --with-mysql=/chroot/mysql --with-curl=/usr/lib64 --enable-zip --with-freetype-dir=/usr/lib64 --with-png-dir --with-jpeg-dir --with-libdir=lib64 --with-gnu-ld --with-iconv=/usr/local/lib which yields the following result: checking for iconv support... yes configure: error: Please reinstall the iconv library. Configure runs fine when I omit the path in the --with-iconv directive, but that will use glibc's iconv, which results in the following failed tests when running make check: Bug #16069 (ICONV transliteration failure) [ext/iconv/tests/bug16069.phpt] iconv stream filter [ext/iconv/tests/iconv_stream_filter.phpt] Test session_decode() function : variation [ext/session/tests/session_decode_variation3.phpt] Test session_encode() function : variation [ext/session/tests/session_encode_variation8.phpt] Test tempnam() function: usage variations - permissions( to 0777) of dir [ext/standard/tests/file/tempnam_variation4.phpt] htmlentities() test 2 (setlocale / fr_FR.ISO-8859-15) [ext/standard/tests/strings/htmlentities02.phpt] (warn: possibly braindead libc) htmlentities() test 4 (setlocale / ja_JP.EUC-JP) [ext/standard/tests/strings/htmlentities04.phpt] (warn: possibly braindead libc) htmlentities() test 15 (setlocale / KOI8-R) [ext/standard/tests/strings/htmlentities15.phpt] (warn: possibly braindead libc) Any thoughts/suggestions/ideas on how to solve this would be greatly appreciated! Regards, Ro Although this not strictly a PHP question you could try to update first. #yum update Just in case something went wrong -- Thodoris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Authentication by client certificate
Hi there, I would like to create a application that can be able to authenticate by client certificate. Can I make this by apache/php? Anyone can recomend me documantation? Thanks, JCampos -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Java / PHP Bridge
-Original Message- From: c...@l-i-e.com [mailto:c...@l-i-e.com] Sent: Friday, January 23, 2009 9:02 AM To: php-general@lists.php.net 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java / PHP Bridge
c...@l-i-e.com 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 :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java / PHP Bridge
And vice-versa: Any PHP functionality that needs to be called from Java can be a web service using whatever weapon you find suitable. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java / PHP Bridge
c...@l-i-e.com 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] process creation
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] process creation
On Fri, Jan 23, 2009 at 3:47 PM, bruce bedoug...@earthlink.net 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 alexan...@gaigalas.net http://Alexandre.Gaigalas.Net
Re: [PHP] process creation
2009/1/23 bruce bedoug...@earthlink.net 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;$iCHILDREN_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;$iCHILDREN_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
[PHP] Re: process creation
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 bedoug...@earthlink.net wrote in message news:156301c97d82$b33698d0$0301a...@tmesa.com... 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java / PHP Bridge
On Fri, Jan 23, 2009 at 10:02 AM, c...@l-i-e.com 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
RE: [PHP] Java / PHP Bridge
-Original Message- From: Bastien Koert [mailto:phps...@gmail.com] Sent: Friday, January 23, 2009 1:13 PM To: c...@l-i-e.com Cc: php-general@lists.php.net Subject: Re: [PHP] Java / PHP Bridge On Fri, Jan 23, 2009 at 10:02 AM, c...@l-i-e.com 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Java / PHP Bridge
-Original Message- From: Boyd, Todd M. Sent: Friday, January 23, 2009 1:44 PM To: 'Bastien Koert' Cc: php-general@lists.php.net Subject: RE: [PHP] Java / PHP Bridge -Original Message- From: Bastien Koert [mailto:phps...@gmail.com] Sent: Friday, January 23, 2009 1:13 PM To: c...@l-i-e.com Cc: php-general@lists.php.net 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] process creation
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:torokal...@gmail.com] Sent: Friday, January 23, 2009 10:09 AM To: bruce Cc: php-general@lists.php.net Subject: Re: [PHP] process creation 2009/1/23 bruce bedoug...@earthlink.net 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;$iCHILDREN_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;$iCHILDREN_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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] process creation
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: process creation
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; } ? 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
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