On Thursday, I updated my PostgreSQL installation from version 7.1.3 to 
version 7.3. Generally, nothing changed, the databases still contain the 
appropriate data, and most of my PHP scripts continued to run flawlessly. 
Great. Mostly. Some scripts did apparently get broken. 

For instance, in a photo-album script I had written, I started seeing errors 
that seemed to indicate that the TCP/IP connections between Apache/PHP and 
PostgreSQL were being lost during the processing of the script. Now, the 
script in question, and the area that generated the error does take a while 
to process; a lot of data such as links to images, and image caption 
information is being returned and placed into a tabular format. While I have 
seen this take as long as 30 seconds to process and render the page, I don't 
believe that the processing time limit is being hit to generate the errors. 
Considering that I didn't update PHP from 4.2.3 to 4.3.0 until today, I'm not 
sure that it's a PHP error directly.

Has anyone else encountered an error such as the first one below? (The 
subsequent errors I'm sure are caused by the disconnect.) When I first 
started seeing the errors, I added a little bit of code to check the 
connection status. If the connection status wasn't OK, then it would 
reconnect, and reissue the query. That eliminated almost all of the errors, 
but this one remains even after I duplicated the check/reconnect code and 
placed it just above the line that triggered the error message.

Warning: pg_query() [function.pg-query]: Query failed: 
server closed the connection unexpectedly This probably 
means the server terminated abnormally before or while 
processing the request. . in /home/mogami/www/special/
photoman.php on line 257

Warning: pg_num_rows(): supplied argument is not a valid 
PostgreSQL result resource in /home/mogami/www/special
/photoman.php on line 258
Warning: pg_free_result(): supplied argument is not a 
valid PostgreSQL result resource in /home/mogami/www/
special/photoman.php on line 272

Any and all help is appreciated. Here is a code fragment:
//query to determine how many pictures are in the database, 
for ($i=0; $i<$picturecount; $i++) {//this isn't the actual loop, but gives 
you the general idea
if (pg_connection_status($db)!=PGSQL_CONNECTION_OK) {
        $pq=pg_query($db,"select *,extract(epoch from takenon) as pdate from 
picture_table order by picture_id;");
        $db=pg_connect("dbname=$dbname host= user=user password=
$aq=pg_query($db,"select * from album_contents where picture_id=$pi->
picture_id order by album_id;");
if ($ac>0) {
        for ($j=0; $j<$ac; $j++) {
                $anq=pg_query($db,"select * from album_table where album_id=$ai->
} else {
        print(" None");


By the time I see the error currently, the $i (outside) loop has gone through 
80-90 iterations, then I see the error once, and the remaining iterations of 
the loop don't exhibit the error. That's probably the strangest part of this 


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to