php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15323 pg_connect failing on iPlanet 4.1 nsapi
Submitted: 2002-02-01 09:10 UTC Modified: 2002-02-02 00:03 UTC
From: daver at qunara dot com Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 4.1.1 OS: Solaris 2.8
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daver at qunara dot com
New email:
PHP Version: OS:

 

 [2002-02-01 09:10 UTC] daver at qunara dot com
Revisiting bug #15282, I am unable to connect to a remote PostgreSQL database using server parsed php. I can connect when the script is run:

	a). On the command line
	b). As a CGI binary
	c.) Using a perl script
	d.) Using psql

Postmaster on the remote server IS running with the '-i' option, even though the error message in the web server logs reads:

     [29/Jan/2002:22:50:18] info (14848): for host b-39-117-res1.mts.net
      trying to POST /members.php, PHP_log_message reports: PHP Warning: 
      Unable to connect to PostgreSQL server:  connectDBStart() -- connect()
      failed: No such file or directory
              Is the postmaster running (with -i) at 'db1'
              and accepting connections on TCP/IP port 5432?
       in /usr/local/etc/httpd/htdocs/cardp.ca/members.php on line 100

No other errors appear and the server keeps on running.

The results of running snoop on the interfaces reveals that instead of the expected SYN/ACK, the system initiating the connection sends SYN/RST.

The connection fails identically when using either pg_connect or pg_pconnect.

Php configuration is as shown below, taken from the original report. As well, the contents of the script are included.

After the bug had been closed as bogus, I asked yohgaki@php.net if he could be more specific in his diagnosis that this behaviour is expected and in the manual. His only reply was that postgres needs to be run using the -i option, which I have already stated is the case. If it weren't, none of the other connections would suceed either.

Connections from the sames server to the same remote database using mysql as the database do not fail. Niether does running the script using apache as the web server. Unfortunately, these are not valid options in our production environment.

Any insight would be greatly appreciated.

- Dave Ruppel

From bug #15282:

   [29 Jan 1:56pm] daver@qunara.com 

      When attempting to connecting to a remote database using
      pg_connect(host=dbhost user=dbuser dbname=dbname), the operation fails.

      I can connect using psql from the command line or through a perl script
      as any user. Running php as a CGI binary also works. However, when
      running as an nsapi, the connection fails. A quick look using snoop
      shows that the failed connection appears to be sending SYN/RST instead
      of SYN/ACK (which is what is seen during a successful connection).

      Here's my system details:
              OS: Solaris 2.8
              Web Server: iPlanet 4.1
              PHP version: php 4.1.1
              PHP configure options:
                      ./configure --with-nsapi=/usr/local/iws41 \
                              --with-pgsql=/usr/local/pgsql \
                              --enable-libgcc
              PostgreSQL version: 7.0.3
              
      For what it's worth, connections to a mysql database between the same
      systems works without a hitch.

      Any suggestions would be appreciated.


   [29 Jan 8:42pm] yohgaki@php.net 

      Could you take a look at web server error log? 
      Do you have anything related? (segfault, etc)

      Could you run iPlanet under gdb? (to see if it is exting or
      segfaulting)

      Do you quote connection string?
      Do you get any error message from pg_connect? 
      Do you have multiple libpq? (find / -name "libpq*")

      Do you have the same problem with snapshot?
      http://snaps.php.net/

      Attach *complete* script even if it is a few lines next time.

   [30 Jan 12:11am] daver@qunara.com 

      I've also tried using the current CVS (01/26/2002) with no luck. The are
      no multiple copies of libpq, it's a new system.

      I haven't tried running iPlanet under gdb yet, that'll be something to
      try tommorow.

      In the mean time, here's the error from the logs:

      [29/Jan/2002:22:50:18] info (14848): for host b-39-117-res1.mts.net
      trying to POST /members.php, PHP_log_message reports: PHP Warning: 
      Unable to connect to PostgreSQL server:  connectDBStart() -- connect()
      failed: No such file or directory
              Is the postmaster running (with -i) at 'db1'
              and accepting connections on TCP/IP port 5432?
       in /usr/local/etc/httpd/htdocs/cardp.ca/members.php on line 100

      No other errors appear and the server keeps on running.

      The source of the script (sans-HTML) calling the database follows:

      <?

              $db = pg_connect("host='db1' user='cardp' dbname='cardp'");
              if(!$db) {
                      echo "\nAn error occured connecting to the database.\n";
                      exit;
              }

              if($alpha=="Show All") {
              $query = "SELECT last_name, first_name, address1, address2, address3,
                                              city, province, country, postal_code, email 
                                      FROM members WHERE active = TRUE ORDER BY last_name";
              } else {
              $query = "SELECT last_name, first_name, address1, address2, address3,
                                              city, province, country, postal_code, email 
                                      FROM members WHERE active = TRUE AND last_name LIKE '$alpha%' ORDER
      BY last_name";
              }

              $result = pg_exec($db, $query);
              if(!$result) {
                      echo "An error occured executing the query.\n";
                      exit;
              }

              $numFields = pg_numfields($result);
              $numRows = pg_numrows($result);

              if($numRows > 0) {
                      for ($rowCount=0; $rowCount < $numRows; $rowCount++) {
                              $row = pg_fetch_array($result, $rowCount);
                              if($rowCount % 2) {
                                      print("<tr>\n");
                              } else {
                                      print("<tr class=\"shade\">\n");
                              }
                              print("<td align=left valign=top width=200>");
                              print("<B>" . $row["last_name"] . ", " . $row["first_name"] .
      "</B></td>\n");
                              print("<td align=left valign=top width=200>");
                              if($row["address1"]) {
                                      print($row["address1"] . "<br>\n");
                              }
                              if($row["address2"]) {
                                      print($row["address2"] . "<br>\n");
                              }
                              if($row["address3"]) {
                                      print($row["address3"] . "<br>\n");
                              }
                              print($row["city"] . ", " . $row["province"]);
                              if($row["postal_code"]) {
                                      print(" " . $row["postal_code"] . "<br>\n");
                              }
                              if($row["country"] != "Canada") {
                                      print($row["country"] . "<br>\n");
                              }
                              if($row["email"]) {
                                      print("<a href=\"mailto:" . $row["email"] . "\">" . $row["email"] .
      "</a>\n");
                              }
                              print("</td>\n</tr>\n");
                      }
                      if(!($numRows % 2)) {
                              print("<tr><td colspan=2 class=\"shade\">&nbsp;</td></tr>\n");
                      }
              } else {
                      print("<tr><td align=center valign=middle colspan=2>\n");
                      print("<h2>Sorry</h2>\n");
                      print("<B>There were no results that matched your query.</B>\n");
                      print("<P>Please make another selection.</P>\n");
                      print("</td></tr>\n");
              }

      ?>

      - DR

   [30 Jan 1:24am] yohgaki@php.net 

      This is not a bug but usual result with your configuration.
      Read manual. It's explained :)

   [30 Jan 6:02pm] daver@qunara.com 

      It's in the manual? Could you please be a little more specific? I've
      gone through the manual and cannot find anything regarding these results
      from this configuration.

      I've managed to get this to work on a linux system using the same
      configuration without encountering the same problem. However, this is
      not an option within our current production environment.

Patches

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 13:01:27 2024 UTC