Re: pcntl_fork?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux