pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: chris smith <dmagick@gmail.com>
To: pgsql-php@postgresql.org
Subject: php pcntl functions and postgresql
Date: Sun, 29 Jan 2006 17:37:43 +1100
Message-ID: <3c1395330601282237r7ad3c003r25ba06ca4113b66f@mail.gmail.com> (raw)

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.

Message-ID: <3c1395330601282237r7ad3c003r25ba06ca4113b66f@mail.gmail.com>
Permalink:  ../3c1395330601282237r7ad3c003r25ba06ca4113b66f@mail.gmail.com/
Also on:    postgresql.org/message-id/3c1395330601282237r7ad3c003r25ba06ca4113b66f@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: dmagick@gmail.com
  Subject: Re: php pcntl functions and postgresql
  In-Reply-To: <3c1395330601282237r7ad3c003r25ba06ca4113b66f@mail.gmail.com>
  References: <3c1395330601282237r7ad3c003r25ba06ca4113b66f@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox