[PHP] pcntl_fork behavior with php version 5.1.2
Hi, i got some trouble with a PHP script using pcntl_fork do run some work in background. Runnig my script on my development system (PHP version 5.3.3-7) it behaves like intended. But running it on my production test system (PHP version PHP 5.1.2), i got some strange results. The problem is, that when i logout from my SSH session the console closes not properly, like somethings is kept open. Sadly, updating this old PHP version is not a option... :/ Does anyone have an idea whats going on? Thanks in advance Ralf The script is this: #!/usr/bin/env php ?php $pid = pcntl_fork(); if ($pid == -1) { die('Fork failed!'); } else if($pid 0) { exit(0); // close parent process } else { // child process: while(true) { sleep(10); // do your work -- stripped } } ? do not work with: PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies works with: PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
Re: [PHP] pcntl_fork behavior with php version 5.1.2
On 03/29/2012 12:49 PM, Ralf Gnädinger wrote: Hi, i got some trouble with a PHP script using pcntl_fork do run some work in background. Runnig my script on my development system (PHP version 5.3.3-7) it behaves like intended. But running it on my production test system (PHP version PHP 5.1.2), i got some strange results. The problem is, that when i logout from my SSH session the console closes not properly, like somethings is kept open. Sadly, updating this old PHP version is not a option... :/ Does anyone have an idea whats going on? Thanks in advance Ralf The script is this: #!/usr/bin/env php ?php $pid = pcntl_fork(); if ($pid == -1) { die('Fork failed!'); } else if($pid 0) { exit(0); // close parent process } else { // child process: while(true) { sleep(10); // do your work -- stripped } } ? do not work with: PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies works with: PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH This sounds more like an OS issue then a PHP issue. What are the two OSs involved? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork behavior with php version 5.1.2
On 29 Mar 2012, at 20:49, Ralf Gnädinger wrote: i got some trouble with a PHP script using pcntl_fork do run some work in background. Runnig my script on my development system (PHP version 5.3.3-7) it behaves like intended. But running it on my production test system (PHP version PHP 5.1.2), i got some strange results. The problem is, that when i logout from my SSH session the console closes not properly, like somethings is kept open. Sadly, updating this old PHP version is not a option... :/ Does anyone have an idea whats going on? Thanks in advance Ralf The script is this: #!/usr/bin/env php ?php $pid = pcntl_fork(); if ($pid == -1) { die('Fork failed!'); } else if($pid 0) { exit(0); // close parent process } else { // child process: while(true) { sleep(10); // do your work -- stripped } } ? do not work with: PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies works with: PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH You need to detach the child from the terminal using posix_setsid(). I don't know why it's working on your development machine, but it's probably simply that you're not seeing this issue due to how you access that development machine. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork behavior with php version 5.1.2
development os is Debian GNU/Linux 6.0 test os is SUSE LINUX 10.1 (i586) Am 29. März 2012 23:02 schrieb Jim Lucas li...@cmsws.com: On 03/29/2012 12:49 PM, Ralf Gnädinger wrote: Hi, i got some trouble with a PHP script using pcntl_fork do run some work in background. Runnig my script on my development system (PHP version 5.3.3-7) it behaves like intended. But running it on my production test system (PHP version PHP 5.1.2), i got some strange results. The problem is, that when i logout from my SSH session the console closes not properly, like somethings is kept open. Sadly, updating this old PHP version is not a option... :/ Does anyone have an idea whats going on? Thanks in advance Ralf The script is this: #!/usr/bin/env php ?php $pid = pcntl_fork(); if ($pid == -1) { die('Fork failed!'); } else if($pid 0) { exit(0); // close parent process } else { // child process: while(true) { sleep(10); // do your work -- stripped } } ? do not work with: PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies works with: PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH This sounds more like an OS issue then a PHP issue. What are the two OSs involved? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ http://www.bendsource.com/
Re: [PHP] pcntl_fork behavior with php version 5.1.2
I will try posix_setsid(). Both machines were accessed via a ssh client (e.g. putty or ssh from a other linux box). Thanks for your advice. Am 29. März 2012 23:08 schrieb Stuart Dallas stu...@3ft9.com: On 29 Mar 2012, at 20:49, Ralf Gnädinger wrote: i got some trouble with a PHP script using pcntl_fork do run some work in background. Runnig my script on my development system (PHP version 5.3.3-7) it behaves like intended. But running it on my production test system (PHP version PHP 5.1.2), i got some strange results. The problem is, that when i logout from my SSH session the console closes not properly, like somethings is kept open. Sadly, updating this old PHP version is not a option... :/ Does anyone have an idea whats going on? Thanks in advance Ralf The script is this: #!/usr/bin/env php ?php $pid = pcntl_fork(); if ($pid == -1) { die('Fork failed!'); } else if($pid 0) { exit(0); // close parent process } else { // child process: while(true) { sleep(10); // do your work -- stripped } } ? do not work with: PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies works with: PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH You need to detach the child from the terminal using posix_setsid(). I don't know why it's working on your development machine, but it's probably simply that you're not seeing this issue due to how you access that development machine. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
[PHP] pcntl_fork, catching STDOUT of child?
Hello, PHP noob here. I've been working on writing a script (command-line) that forks a number of children to do various tasks. I've been using pcntl_waitpid inside a loop to wait for the children to exit, act on the results, and fork another copy of the child. Where I seem to be running into trouble is in managing communication between child and parent, so that the parent has an indication of result inside the child. In the past, I've done this in Perl using something along the lines of: open(FILEHANDLE,-|); In Perl, this has the effect of forking the process and attaching the STDOUT of the child to FILEHANDLE on the parent. Thus, when the child exits, I read FILEHANDLE to get the output from the child. Is there a similar way of achieving a similar result in PHP? Am I crazy? So far, I have tried to communicate between the processes using sockets (socket_create_pair). However, this seems to be a dead-end, I get a connection reset by peer when I try to socket_read() from the parent. I assume this is because the socket is closed by the exit of the child. Any insight or criticism is appreciated. -- Thomas Johnson ClaimLynx, Inc. 952-593-5969%20x2302
Re: [PHP] pcntl_fork, catching STDOUT of child?
Have a look at zeromq. http://vimeo.com/20605470 http://zguide.zeromq.org/php:all Hope it helps. On Fri, Jan 20, 2012 at 12:24 AM, Thomas Johnson t...@claimlynx.com wrote: Hello, PHP noob here. I've been working on writing a script (command-line) that forks a number of children to do various tasks. I've been using pcntl_waitpid inside a loop to wait for the children to exit, act on the results, and fork another copy of the child. Where I seem to be running into trouble is in managing communication between child and parent, so that the parent has an indication of result inside the child. In the past, I've done this in Perl using something along the lines of: open(FILEHANDLE,-|); In Perl, this has the effect of forking the process and attaching the STDOUT of the child to FILEHANDLE on the parent. Thus, when the child exits, I read FILEHANDLE to get the output from the child. Is there a similar way of achieving a similar result in PHP? Am I crazy? So far, I have tried to communicate between the processes using sockets (socket_create_pair). However, this seems to be a dead-end, I get a connection reset by peer when I try to socket_read() from the parent. I assume this is because the socket is closed by the exit of the child. Any insight or criticism is appreciated. -- Thomas Johnson ClaimLynx, Inc. 952-593-5969%20x2302
Re: [PHP] pcntl_fork?
On Mon, January 30, 2006 5:33 am, Peter Hoskin wrote: I have written a script to parse a large amount of XML data and insert it into SQL... deals with approx 80,000 rows each time I run it. I cannot successfully complete this script without running out of memory. Is pcntl_fork suitable to overcome this? Probably not... I have been playing with pcntl_fork and became completely stuck trying to select data from a database and spawn a new fork for each row. Later I'll have to use something like shmop so each child knows what row its working on, and will do a series of xml parsing based on supplied data.. a simple example of forking with a foreach this way would be appreciated Woof. A new process getting forked for each row is going to swamp your machine with processes very very very rapidly... First, though, are you running this from the command line CLI interface? Just supply a custom php.ini with memory_limit = 16M or whatever it takes to get the job done and call it quits. If you're trying to run pctl_fork from a web application, you're doomed anyway -- It's not suitable in that environment. You probably could re-write the script to not need so much RAM, by using fopen/fgets to read one LINE at a time, and deal with it, and then move on to the next line. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl_fork?
Hi, I have written a script to parse a large amount of XML data and insert it into SQL... deals with approx 80,000 rows each time I run it. I cannot successfully complete this script without running out of memory. Is pcntl_fork suitable to overcome this? I have been playing with pcntl_fork and became completely stuck trying to select data from a database and spawn a new fork for each row. Later I'll have to use something like shmop so each child knows what row its working on, and will do a series of xml parsing based on supplied data.. a simple example of forking with a foreach this way would be appreciated Regards, Peter Hoskin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork?
Peter Hoskin wrote: Hi, I have written a script to parse a large amount of XML data and insert it into SQL... deals with approx 80,000 rows each time I run it. I cannot successfully complete this script without running out of memory. how much memory do you have set as the max? do you have control over this value? (i.e. is it not locked down by an admin) what are you doing with each row? (I imagine that effectively you only need on row in memory at a time - in which case the memory requirements are probably quite conservative) show us your code if you can :-) Is pcntl_fork suitable to overcome this? it may offer one suitable solution. but I would suggest looking at your code again before adding another level of complexity that may not bee needed (I would suggest that forking would be a good idea to improve the performance by allowing parallel processing but not to fix a crash perse) I have been playing with pcntl_fork and became completely stuck trying to select data from a database and spawn a new fork for each row. Later I'll have to use something like shmop so each child knows what row its working on, and will do a series of xml parsing based on supplied data. I doubt you need shmop given that each child gets a complete copy of the parent processes address space (i.e. all variables, etc that were defined in the parent process will also be available in each child process) there are some examples in the user comments on this page: http://php.net/manual/en/function.pcntl-fork.php a simple example of forking with a foreach this way would be appreciated Regards, Peter Hoskin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork?
Jochem Maas wrote: how much memory do you have set as the max? 512mb do you have control over this value? (i.e. is it not locked down by an admin) yes what are you doing with each row? (I imagine that effectively you From each row, I determine what XML files to fetch and parse... the parser then inserts them into SQL. This is really the second part of the parsing, the first pass fetches the concerned table as XML and parses it. Each XML file I fetch can be between 15-50 rows. only need on row in memory at a time - in which case the memory requirements are probably quite conservative) show us your code if you can :-) It came down to my code I think... wasn't using it appropriately. I read the post 'pcntl functions and database' from this list a few days ago, and it had a good example... so far I've come up with: ? require_once('../private/sql.php'); $pgconnectstring='dbname=' . returndbname() . ' user=' . returndbuser() . ' password=' . returndbpass() . ' host=redback.10mbit.biz'; $database = pg_connect($pgconnectstring); $query = SELECT count(key) AS count FROM tvguide_channels WHERE crawl=true;; $result = pg_query($database,$query); $row = pg_fetch_object($result,0); $childcount = 0; $childrencount = $row-count; while($childcount $childrencount) { $pid = pcntl_fork(); if ( $pid == -1 ) { die(Unable to fork\n); } elseif ($pid == 0) { $childcount++; pcntl_wait($status); continue; } else { echo $childcount . . posix_getpid() . . posix_getppid() .\n; exit(); } } ? Each fork seems to be able to see the value of $childcount... so I just need to create a function to work with a particular row. Having a counter is precisely what I needed as I can then use pg_fetch_object($result,$childcount) Regards, Peter Hoskin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork?
Peter Hoskin wrote: Jochem Maas wrote: how much memory do you have set as the max? 512mb should be enough. :-) just to give it perspective I have a text file I import on at least a weekly basis (someone else does it actually but i wrote the code) that contains 500,000+ lines representing customers each of which is imported/updated into firebird DB (mostly not as fast as mysql) using a transaction. the code works and only chews up about 100Mbs (which is mostly due to the garbage collector not being able to release memory belonging to objects that have circular references) do you have control over this value? (i.e. is it not locked down by an admin) yes what are you doing with each row? (I imagine that effectively you From each row, I determine what XML files to fetch and parse... the parser then inserts them into SQL. This is really the second part of the parsing, the first pass fetches the concerned table as XML and parses it. Each XML file I fetch can be between 15-50 rows. I get the feeling you should be unsetting variables more actively inside your loops. also avoid objects (specifically/especially ones with circular 'references'** - i.e. parent--child type 'references'**) ** - I use 'references' to mean in the general english language sense not in the php sense. although if you're using php4 then most probably your object variables should actually be php-references! only need on row in memory at a time - in which case the memory requirements are probably quite conservative) show us your code if you can :-) It came down to my code I think... wasn't using it appropriately. I read the post 'pcntl functions and database' from this list a few days ago, and it had a good example... so far I've come up with: ? require_once('../private/sql.php'); $pgconnectstring='dbname=' . returndbname() . ' user=' . returndbuser() . ' password=' . returndbpass() . ' host=redback.10mbit.biz'; $database = pg_connect($pgconnectstring); $query = SELECT count(key) AS count FROM tvguide_channels WHERE crawl=true;; $result = pg_query($database,$query); $row = pg_fetch_object($result,0); $childcount = 0; $childrencount = $row-count; while($childcount $childrencount) { $pid = pcntl_fork(); if ( $pid == -1 ) { die(Unable to fork\n); } elseif ($pid == 0) { $childcount++; pcntl_wait($status); continue; } else { echo $childcount . . posix_getpid() . . posix_getppid() .\n; exit(); } } ? Each fork seems to be able to see the value of $childcount... so I just need to create a function to work with a particular row. Having a counter is precisely what I needed as I can then use pg_fetch_object($result,$childcount) moving forward, always nice to make progress :-) Regards, Peter Hoskin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork?
Chris wrote: Hi Peter, If you can get it working can you send me a sample? Certainly... database connections must be CLEAN! Meaning, you should close them when they're no longer needed. Additionally, each fork should open its own DB connection. My completed code: ? require_once('../private/sql.php'); require_once('include-crawl.php'); if (phpversion() 5) { date_default_timezone_set('UTC'); } $pgconnectstring='dbname=' . returndbname() . ' user=' . returndbuser() . ' password=' . returndbpass() . ' host=redback.10mbit.biz'; $database = pg_connect($pgconnectstring); $pquery = SELECT count(key) AS count FROM tvguide_channels WHERE crawl=true;; $presult = pg_query($database,$pquery); $row = pg_fetch_object($presult,0); pg_close($database); $childcount = 0; $childrencount = $row-count; while($childcount $childrencount) { $pid = pcntl_fork(); if ( $pid == -1 ) { die(Unable to fork\n); } elseif ($pid == 0) { $childcount++; sleep(10); continue; } else { $db = pg_connect($pgconnectstring); $cquery = SELECT id FROM tvguide_channels WHERE crawl=true ORDER BY key ASC LIMIT 1 OFFSET .$childcount.;; $cresult = pg_query($db, $cquery); if ($cresult (pg_num_rows($cresult) == 1)) { $row = pg_fetch_object($cresult,0); //echo $childcount . . $row-id . . posix_getpid() . . posix_getppid() .\n; tvxml_parsechannel($db,$row-id); pg_close($db); } else { echo $childcount . . pg_last_error($db) .\n; } exit(); } } ? Try this: ?php declare(ticks=1); $time = time(); $childcount = 0; $childrencount = 10; while($childcount $childrencount) { $pid = pcntl_fork(); if ( $pid == -1 ) { die(error\n); } if ($pid == 0) { $childcount++; pcntl_wait($status); } else { $connection_string = 'dbname= user= password='; if (!$connection_result = pg_pconnect($connection_string)) { echo 'Unable to connect: ' . pg_last_error() . \n; exit(); } echo Connected ok\n; $qry = select version() AS version; $result = pg_query($connection_result, $qry); if (!$result) { echo error: . pg_last_error() . \n; } else { $row = pg_fetch_assoc($result); echo $row['version'] . \n; } pg_close($connection_result); exit(); } } echo 'took ' . (time() - $time) . ' seconds' . \n; ? IE: you were connecting to the DB too early, at a point where it wasn't needed. On another note, my new script that forks uses approx 24mb of memory - a very nice cut down on its usage :D Regards, Peter Hoskin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork?
Sharing variables between processes and their forks needs something like shmop or systemv shared memory. Additionally, shared memory only lets you share basic variables and not database resources... or as far as I understand. So, each fork is required to create its own connection to the database if you want to use it. Chris wrote: Hi Peter, So each thread accesses it's own database connection (ie it'll open $childrencount connections). Is that what you want? I was trying to get it to share the db connection over the parent and children threads. (The strange thing is the mysql equivalent of my version works ok - it forks the db connection properly and it's still accessible). The first SELECT statement in my code, and where you originally had placed your db connection... that would be executed by each fork. You're probably already getting multiple connections in mysql anyway. This is precisely the reason you want to ensure you close of db connections after you do not need them. I found that connecting to sql before the if ($pid) statements would make the database resource unusable, which is why I've closed it and reopened it later on in the script. Hope that helps! Regards, Peter Hoskin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork and reading from childs stdout
Hi Richard, Thanks for the response. I'll try out the fifo. Tom [EMAIL PROTECTED] wrote: On Sun, June 12, 2005 12:57 pm, Tom Fishwick said: I have a script that spawns off a bunch of children with pcntl_fork(), but I can't figure out how to connect up a pipe from the parent to each childs stdout and stdin. In c I would use pipe,close and dup... This might help: http://php.net/posix-mkfifo How you would tie stdout to your named pipe... Or perhaps you could http://php.net/exec something in each process to re-direct or tee stdin/stdout to your named pipes. Or... I dunno, really, just guessing. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl_fork and reading from childs stdout
Hi All, I have a script that spawns off a bunch of children with pcntl_fork(), but I can't figure out how to connect up a pipe from the parent to each childs stdout and stdin. In c I would use pipe,close and dup... any ideas would be appreciated. (that don't involve using proc_open() :-) Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork and reading from childs stdout
On Sun, June 12, 2005 12:57 pm, Tom Fishwick said: I have a script that spawns off a bunch of children with pcntl_fork(), but I can't figure out how to connect up a pipe from the parent to each childs stdout and stdin. In c I would use pipe,close and dup... This might help: http://php.net/posix-mkfifo How you would tie stdout to your named pipe... Or perhaps you could http://php.net/exec something in each process to re-direct or tee stdin/stdout to your named pipes. Or... I dunno, really, just guessing. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork and reading from childs stdout
Tom Fishwick wrote: Hi All, I have a script that spawns off a bunch of children with pcntl_fork(), but I can't figure out how to connect up a pipe from the parent to each childs stdout and stdin. In c I would use pipe,close and dup... any ideas would be appreciated. (that don't involve using proc_open() :-) Tom http://www.php.net/popen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork() hangs with FUTEX_WAIT
Well, but I don't use multithreading? PHP is running as CLI exec, not compiled into Apache... That's my configure command: ./configure --enable-pcntl --with-curl --with-mysql Or do I have to care for thread safety anyway? Regards, Steve Richard Lynch wrote: Steve wrote: I have a program which creates a lot of children over the time, which terminate themselves after they are finished. After some time however, the parent process hangs; apparently in pcntl_fork(). The child from this fork, however, seems to run normally. An strace on the parent shows futex(0x471cb0, FUTEX_WAIT, 2, NULL The program runs on PHP 5.0.3-cli and Linux 2.6. Has anyone an idea what could be the reason for that hang? Didja try: http://www.google.com/search?q=FUTEX_WAIT I did and got: http://lists.boost.org/MailArchives/boost-users/msg07650.php So I'm guessing you didn't compile *everything* on your PHP/Apache system with multi-thread support. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork() hangs with FUTEX_WAIT
Steve wrote: Well, but I don't use multithreading? PHP is running as CLI exec, not compiled into Apache... That's my configure command: ./configure --enable-pcntl --with-curl --with-mysql Or do I have to care for thread safety anyway? For all I know (not much) --enable-pcntl may imply that you are doing multi-threading... Doesn't it kind of have to? I mean, isn't that what pcntl *DOES*? Allow you to 'fork' a new process, which has its own separate thread, by definition? Or maybe processes and threads are different enough that you're okay on this one... If so, you have to re-compile cURL and MySQL with multi-threading turned on as well, at least as I understand the Google answers. Or maybe you turned on multi-threading with cURL and MySQL when you compiled them for Apache, but now you need that *OFF* to work with your non-thread CLI PHP binary. Maybe there's a command line tool to ask a .so file if it's threaded or not? Maybe even just 'file foo.so' will tell you??? -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl_fork() hangs with FUTEX_WAIT
I have a program which creates a lot of children over the time, which terminate themselves after they are finished. After some time however, the parent process hangs; apparently in pcntl_fork(). The child from this fork, however, seems to run normally. An strace on the parent shows futex(0x471cb0, FUTEX_WAIT, 2, NULL The program runs on PHP 5.0.3-cli and Linux 2.6. Has anyone an idea what could be the reason for that hang? Thanks in advance, Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork() hangs with FUTEX_WAIT
Steve wrote: I have a program which creates a lot of children over the time, which terminate themselves after they are finished. After some time however, the parent process hangs; apparently in pcntl_fork(). The child from this fork, however, seems to run normally. An strace on the parent shows futex(0x471cb0, FUTEX_WAIT, 2, NULL The program runs on PHP 5.0.3-cli and Linux 2.6. Has anyone an idea what could be the reason for that hang? Didja try: http://www.google.com/search?q=FUTEX_WAIT I did and got: http://lists.boost.org/MailArchives/boost-users/msg07650.php So I'm guessing you didn't compile *everything* on your PHP/Apache system with multi-thread support. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl_fork doesn't work
I'm trying to use pcntl_fork on php 4.3.10, but it says Call to undefined function: pcntl_fork() in test.php on line 3. The manual says pcntl is present in php = 4.1.0. I have 4.3.10, just the standard installation included on fedora core 3. I've done all the standard stuff - google'd, searched mailing list archive, looked through phpinfo() (didn't find anything relevant). Why wouldn't pcntl be working? Is there any other way for me to fork a process or thread? -John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork doesn't work
John Davin wrote: I'm trying to use pcntl_fork on php 4.3.10, but it says Call to undefined function: pcntl_fork() in test.php on line 3. The manual says pcntl is present in php = 4.1.0. I have 4.3.10, just the standard installation included on fedora core 3. I've done all the standard stuff - google'd, searched mailing list archive, looked through phpinfo() (didn't find anything relevant). Why wouldn't pcntl be working? Is there any other way for me to fork a process or thread? Sometimes you can use exec(... ) to fork... It's probably not really a good idea as others have stated. Most web log analyzers look up and cache IP-domain-name data for this exact same reason. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl_fork and classes
Is it possible to pcntl_fork() withing a class? Basically I want a web page to load, and when the class is called in the page, it can fork and the child can run, allowing the webpage to finish, but the class process can continue 'till it's done. Is this possible? Would I put the fork in the constructor? Would calling the class methods after it forked work the same way? -Josh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork and classes
On Sun, 27 Jun 2004 15:31:59 -0500 (CDT), [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Is it possible to pcntl_fork() withing a class? Basically I want a web page to load, and when the class is called in the page, it can fork and the child can run, allowing the webpage to finish, but the class process can continue 'till it's done. Is this possible? Would I put the fork in the constructor? Would calling the class methods after it forked work the same way? When you fork, you get two exact copies of the same process with only one difference. The value returned from pcntl_fork(). As for the child processes finishing in the backgroundI'm not sure. The entire process may not be able to finish unless the child is finished OR the child may just exit when the parent does (when the user clicks stop) OR the web browser may look like it's still loading but the main page will be done. I would suggest doing a test. -- paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl_fork() under linux with phpcli
well... playing with fork() in a phpcli script, i got some troubles with childs... anybody knows how to dont get zombies/defuncts with SIGCHLD and SIGCLD ignoring ? dont worked for me =/ i dont want to know how many childs are running, or if they terminated or not... i want only to make childs :D ignoring SIGCHLD in perl works finely... is there anything about the phped-layer to syscalls access ? duh.. comments are welcome =) []'s Daniel Souza ? declare (ticks = 1); //original sighangler, not used anymore... i know :) function sig_handler($signo) { out([+] SIG: $signo\n); $pid = pcntl_waitpid(-1, $status, WNOHANG); if ($signo == SIGCHLD) out([+] SIGCHLD PID:$pid\n); if ($signo == SIGCLD) out([+] SIGCLD PID: $pid\n); //posix_kill($pid, SIGTERM); } pcntl_signal(SIGCLD, SIG_IGN); pcntl_signal(SIGCHLD, SIG_IGN); $n = 0; while (1) { $n++; $pid = pcntl_fork(); if ($pid == -1) { out([+] error in fork.\n); exit(-1); } if ($pid == 0) { // child... $pid = posix_getpid(); out([+] im the number $n !!!\n); // do some job... exit(0); } else { // im parent... if (($n % 100) == 0) // we wait 10sec to create another childs { out([+] giving some time for childs...\n); sleep(10); $n = 0; out([+] making more childs ;D\n); } } } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl_fork
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, Does php 4.2.3 support pcntl_fork from the php compiles as module in apac= he? I have configured php with --enable-pcntl and it says: Call to undefined function: pcntl_fork() Thanks, - -- Negrea Mihai http://www.negrea.net -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9/zkM8hhhNOp8KlQRAt17AJ96DpQKFwlqN+Sl2wN03mFI7UKaKACgjgyx Xs9KP0mSYLY3fyDGeYBw07U= =Fxs2 -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork
Negrea Mihai wrote: I have configured php with --enable-pcntl and it says: Either php being used is not compiled with this option (what does phpinfo show? Did you restart Apache)? Call to undefined function: pcntl_fork() Or pcntl_fork() is not a function provided with --enable_pcntl. I can't think of any other possiblities. HTH Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 My phpinfo shows in the upper part in the configure line that it has been compiled with --enable-pcntl I have Apache 2.0 from RH8.0 And.. it works from the command line if I use the php binary On Tuesday 17 December 2002 17:33, Chris Hewitt wrote: Negrea Mihai wrote: I have configured php with --enable-pcntl and it says: Either php being used is not compiled with this option (what does phpinfo show? Did you restart Apache)? Call to undefined function: pcntl_fork() Or pcntl_fork() is not a function provided with --enable_pcntl. I can't think of any other possiblities. HTH Chris - -- Negrea Mihai http://www.negrea.net -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9/0Kx8hhhNOp8KlQRApI5AJkBwsUzB/p1fU/yYgXJ3pCEJs6QUwCfbe0k AVb/78TX1n4ZewT/i2Xn/6o= =HMVZ -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 forgot to say: I have php 4.2.3 On Tuesday 17 December 2002 17:28, Negrea Mihai wrote: My phpinfo shows in the upper part in the configure line that it has been compiled with --enable-pcntl I have Apache 2.0 from RH8.0 And.. it works from the command line if I use the php binary On Tuesday 17 December 2002 17:33, Chris Hewitt wrote: Negrea Mihai wrote: I have configured php with --enable-pcntl and it says: Either php being used is not compiled with this option (what does phpinfo show? Did you restart Apache)? Call to undefined function: pcntl_fork() Or pcntl_fork() is not a function provided with --enable_pcntl. I can't think of any other possiblities. HTH Chris - -- Negrea Mihai http://www.negrea.net -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9/0ND8hhhNOp8KlQRAkxZAKCAsCJhmSv9pAsmG3JRLBmGvUFrKwCeIOGg fNkYcsz9W5f71rawYmwE9l8= =qhRx -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pcntl_fork
Negrea Mihai wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 My phpinfo shows in the upper part in the configure line that it has been compiled with --enable-pcntl I have Apache 2.0 from RH8.0 This seemed a bit wierd so I looked further. From the manual (http://www.php.net/manual/en/ref.pcntl.php) : Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a webserver environment and unexpected results may happen if any Process Control functions are used within a webserver environment. And.. it works from the command line if I use the php binary That is where it should work. So, although it may not be as you expected, all is as it should be. Regards Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pcntl_fork()
Using this function, say I had two processes running, the parent accepting connections on an inet socket, is it possible for the parent to pass this socket connection onto the already existing child? -- Richard Heyes I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones. - Albert Einstein -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]