[thelist] PHP & PostgreSQL question: why is the connection to pg_exec lost?

Ivo P ipletikosic at gmail.com
Fri Dec 16 17:04:15 CST 2005


Hello all,

I.m running a very intensive script with about 40K queries but at
about 38K queries the database connection is no longer valid. How is
this lifetime determined? Is it by the number of queries or the
duration of the script or the duration of the connection?

ex.

$conn = pg_connect(...some connection string...);

foreach($array_user_ids as $user_id) {
    $select_statement = <...construct a select...>;
    $result=pg_query($conn,$select_statement);
    if(! $result) {
        $err_msg = pg_last_error($conn);
        die("ERROR: $err_msg\n");
    }

    // do something with result...
}

at the 38,453th query the script dies with:

PHP Warning:  pg_query(): supplied argument is not a valid PostgreSQL
link resource in /chroot/httpd/sample.php on line 17
PHP Warning:  pg_last_error(): supplied argument is not a valid
PostgreSQL link resource in /chroot/httpd/sample.php on line 19
ERROR:

I solved the symptom by splitting up the queries in batches but I am
still curious as to where and why the limit is hit..

This is on a dedicated machine so the script is the only connection to
PostgreSQL, the maximum connections in php.ini is 32 and the time
limit for the script is set to 0.

Thanks,

Ivo



More information about the thelist mailing list