From: | chris smith <dmagick(at)gmail(dot)com> |
---|---|
To: | pgsql-php(at)postgresql(dot)org |
Subject: | php pcntl functions and postgresql |
Date: | 2006-01-29 06:37:43 |
Message-ID: | 3c1395330601282237r7ad3c003r25ba06ca4113b66f@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
Hi all,
This is a bit of a strange one and I'm not sure where to start looking, so
any / all suggestions welcome.
I'm using php with the process control functions and want each thread to
share the main db connection.
Running php 5.1.2 and postgresql 8.1.2.
My code looks like:
#!/usr/local/php/bin/php -q
<?php
declare(ticks=1);
$time = time();
$connection_string = 'dbname=xxxxxxxx user=xxxxxxxx password=';
if (!$connection_result = pg_pconnect($connection_string)) {
echo 'Unable to connect: ' . pg_last_error() . "\n";
exit();
}
echo "Connected ok\n";
$childcount = 0;
$childrencount = 10;
while($childcount < $childrencount) {
$pid = pcntl_fork();
if ( $pid == -1 ) {
die("error\n");
}
if ($pid == 0) {
$childcount++;
usleep(100);
pcntl_wait($status);
} else {
echo "\nchildcount: " . $childcount . "\n";
var_dump($connection_result);
$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";
}
exit();
}
}
echo 'took ' . (time() - $time) . ' seconds' . "\n";
?>
When I run it I get:
childcount: 0
resource(1) of type (pgsql link persistent)
PostgreSQL 8.1.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.5(Debian 1:
3.3.5-13)
childcount: 1
resource(1) of type (pgsql link persistent)
error: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
childcount: 2
resource(1) of type (pgsql link persistent)
error: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The 'resource(1) of type (pgsql link persistent)' shows the connection is
still valid as far as php is concerned.
In the postgresql logs I get:
LOG: connection received: host=[local]
LOG: connection authorized: user=xxxxxx database=xxxxxx
LOG: statement: select version() AS version
LOG: duration: 3.516 ms
LOG: duration: 3.516 ms statement: select version() AS version
LOG: disconnection: session time: 0:00:00.02 user=xxxxxx database=xxxxxx
host=[local]
Turning up debugging / logs in postgresql didn't show anything extra.
So I think either:
a) I'm doing something wrong
b) It's a bug in php
c) It's a bug in the postgresql php "driver"
I don't think it's a or b because I change it all to mysql and it works, it
doesn't drop the connection like it is here.
I'm not sure where to start looking from here... so any ideas/comments
please send them through!
Thanks,
Chris.
From | Date | Subject | |
---|---|---|---|
Next Message | Przemek Kowalczyk | 2006-02-03 04:15:33 | php and postgresql on windows |
Previous Message | Abhishek Goyal | 2006-01-25 14:20:20 | Re: Apache, Php and postgresql on windows |