Обсуждение: PHP/postgreSQL
I'm running PHP/mySQL via a web hosting service. I require my PHP scripts to access an external PostgreSQL database. I have the PostgreSQL server setup to accept connections from anyone: [pg_hba_conf] # TYPE DATABASE USER CIDR-ADDRESS METHOD host all all 0.0.0.0/0 trust [--] I've tested this connection via pgAdminIII and I'm able to connect using this IP, but when I try to connect via php from the hosted webpage... My php script is simple: <?php $conn_string = "host=24.85.82.xxx port=5432 dbname=PGSQL1 user=postgres password=xxx"; $dbconn = pg_connect($conn_string); if ($dbconn) { print "Successfully connected to: " . pg_host($dbconn) . "<br/>\n"; } else { print pg_last_error($dbconn); exit; } pg_close($dbconn); ?> But I'm foiled by: Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Operation timed out Is the server running on host "24.85.82.xxx" and accepting TCP/IP connections on port 5432? in /usr/local/psa/home/vhosts/weaktight.com/httpdocs/mytest.php on line 13 Any thoughts or suggestions would be greatly appreciated. I'm not very experienced with any of this stuff. Thanks.
Are you sure your isp isn't blocking access? First thought to come to mind is shaw cable might be blocking port 5432. Can you try and telnet to the box from your server on port 5432? Also check to make sure pgsql is listening on tcp/ip. Also if you're a home shaw customer, are you behind a nat router? Have you opened up access on the nat router to get to your box behind it? HTH, Gavin On Feb 4, 2006, at 2:14 PM, vince@weaktight.com wrote: > I'm running PHP/mySQL via a web hosting service. I require my PHP > scripts to > access an external PostgreSQL database. > > I have the PostgreSQL server setup to accept connections from anyone: > [pg_hba_conf] > > # TYPE DATABASE USER CIDR-ADDRESS METHOD > host all all 0.0.0.0/0 trust > > [--] > > I've tested this connection via pgAdminIII and I'm able to connect > using this > IP, but when I try to connect via php from the hosted webpage... > > My php script is simple: > > <?php > $conn_string = "host=24.85.82.xxx port=5432 dbname=PGSQL1 > user=postgres > password=xxx"; > > $dbconn = pg_connect($conn_string); > > if ($dbconn) { > > print "Successfully connected to: " . pg_host($dbconn) . "<br/>\n"; > > } else { > > print pg_last_error($dbconn); > exit; > } > > pg_close($dbconn); > ?> > > But I'm foiled by: > > Warning: pg_connect(): Unable to connect to PostgreSQL server: > could not connect > to server: Operation timed out Is the server running on host > "24.85.82.xxx" and > accepting TCP/IP connections on port 5432? in > /usr/local/psa/home/vhosts/weaktight.com/httpdocs/mytest.php on > line 13 > > Any thoughts or suggestions would be greatly appreciated. I'm not very > experienced with any of this stuff. > > Thanks. > > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster
So the setup is as follows: I have a web server hosted by stormweb that runs the PHP scripts. On one of my local machines behind a router, I have a postgreSQL server service setup. If I run pgAdminIII on the postgreSQL server machine using the external IP to connnect (24.85.82.xxx), it works ONLY with these postgreSQL server settings: >> # TYPE DATABASE USER CIDR-ADDRESS METHOD >> host all all 0.0.0.0/0 trust (I believe this is the setting that makes "sure pgsql is listening on tcp/ip") I have enabled port forwarding on my router to forward 5432 to the proper machine. Additionally, when I was starting, I was not able to connect from my local server machine to itself via 24.85.82.xxx until I allowed the 5432 port to pass through the window's firewall. (I've tried disabling that as well) Given that it connects, can I assume that it's taking an external route to get there and that shaw is allowing this traffic? (otherwise the firewall wouldn't have any effect?) Are there any possible problems from the web server machine that might be preventing the connection? Quoting "Gavin M. Roy" <gmr@ehpg.net>: > Are you sure your isp isn't blocking access? First thought to come > to mind is shaw cable might be blocking port 5432. Can you try and > telnet to the box from your server on port 5432? Also check to make > sure pgsql is listening on tcp/ip. Also if you're a home shaw > customer, are you behind a nat router? Have you opened up access on > the nat router to get to your box behind it? > > HTH, > > Gavin > > On Feb 4, 2006, at 2:14 PM, vince@weaktight.com wrote: > >> I'm running PHP/mySQL via a web hosting service. I require my PHP >> scripts to >> access an external PostgreSQL database. >> >> I have the PostgreSQL server setup to accept connections from anyone: >> [pg_hba_conf] >> >> # TYPE DATABASE USER CIDR-ADDRESS METHOD >> host all all 0.0.0.0/0 trust >> >> [--] >> >> I've tested this connection via pgAdminIII and I'm able to connect >> using this >> IP, but when I try to connect via php from the hosted webpage... >> >> My php script is simple: >> >> <?php >> $conn_string = "host=24.85.82.xxx port=5432 dbname=PGSQL1 user=postgres >> password=xxx"; >> >> $dbconn = pg_connect($conn_string); >> >> if ($dbconn) { >> >> print "Successfully connected to: " . pg_host($dbconn) . "<br/>\n"; >> >> } else { >> >> print pg_last_error($dbconn); >> exit; >> } >> >> pg_close($dbconn); >> ?> >> >> But I'm foiled by: >> >> Warning: pg_connect(): Unable to connect to PostgreSQL server: >> could not connect >> to server: Operation timed out Is the server running on host >> "24.85.82.xxx" and >> accepting TCP/IP connections on port 5432? in >> /usr/local/psa/home/vhosts/weaktight.com/httpdocs/mytest.php on line 13 >> >> Any thoughts or suggestions would be greatly appreciated. I'm not very >> experienced with any of this stuff. >> >> Thanks. >> >> >> ---------------------------(end of broadcast)--------------------------- >> TIP 2: Don't 'kill -9' the postmaster > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >
> Can you try and telnet to the box from your server on port 5432? I don't have shell access to the webserver machine. I can connect from one of my local machines via: telnet 24.85.82.xxx 5432 It brings up an empty console that closes after I enter input. Quoting "Gavin M. Roy" <gmr@ehpg.net>: > Are you sure your isp isn't blocking access? First thought to come > to mind is shaw cable might be blocking port 5432. Can you try and > telnet to the box from your server on port 5432? Also check to make > sure pgsql is listening on tcp/ip. Also if you're a home shaw > customer, are you behind a nat router? Have you opened up access on > the nat router to get to your box behind it? > > HTH, > > Gavin > > On Feb 4, 2006, at 2:14 PM, vince@weaktight.com wrote: > >> I'm running PHP/mySQL via a web hosting service. I require my PHP >> scripts to >> access an external PostgreSQL database. >> >> I have the PostgreSQL server setup to accept connections from anyone: >> [pg_hba_conf] >> >> # TYPE DATABASE USER CIDR-ADDRESS METHOD >> host all all 0.0.0.0/0 trust >> >> [--] >> >> I've tested this connection via pgAdminIII and I'm able to connect >> using this >> IP, but when I try to connect via php from the hosted webpage... >> >> My php script is simple: >> >> <?php >> $conn_string = "host=24.85.82.xxx port=5432 dbname=PGSQL1 user=postgres >> password=xxx"; >> >> $dbconn = pg_connect($conn_string); >> >> if ($dbconn) { >> >> print "Successfully connected to: " . pg_host($dbconn) . "<br/>\n"; >> >> } else { >> >> print pg_last_error($dbconn); >> exit; >> } >> >> pg_close($dbconn); >> ?> >> >> But I'm foiled by: >> >> Warning: pg_connect(): Unable to connect to PostgreSQL server: >> could not connect >> to server: Operation timed out Is the server running on host >> "24.85.82.xxx" and >> accepting TCP/IP connections on port 5432? in >> /usr/local/psa/home/vhosts/weaktight.com/httpdocs/mytest.php on line 13 >> >> Any thoughts or suggestions would be greatly appreciated. I'm not very >> experienced with any of this stuff. >> >> Thanks. >> >> >> ---------------------------(end of broadcast)--------------------------- >> TIP 2: Don't 'kill -9' the postmaster > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >
On Sat, 2006-02-04 at 18:57 -0500, vince@weaktight.com wrote: > > Can you try and telnet to the box from your server on port 5432? > > I don't have shell access to the webserver machine. I can connect from one of > my local machines via: telnet 24.85.82.xxx 5432 > > It brings up an empty console that closes after I enter input. > ok.. in all of your tests you have been connecting across your local network, which takes the shaw devices out of the equation. if you are able to connect with pgAdmin3 via ip address (and from your message it seems that you are), my guess is that pgsql is accepting connections via tcp/ip. since you are attempting to connect to pgsql on your local network from your web server (which is hosted elsewhere) and it times out, this tells me that there is a device in the middle someplace that is firewalling the packets. you are *unlikely* to convince shaw to make firewall changes (if that is what is happening) so you can do this. ok.. now the hopefully easy question :): why are you trying to set things up this way? regards, J -- Jeff MacDonald Zoid Technologies, http://zoidtechnologies.com/
Quoting Jeff MacDonald <jam@zoidtechnologies.com>: > ok.. in all of your tests you have been connecting across your local > network, which takes the shaw devices out of the equation. > > if you are able to connect with pgAdmin3 via ip address (and from your > message it seems that you are), my guess is that pgsql is accepting > connections via tcp/ip. > > since you are attempting to connect to pgsql on your local network from > your web server (which is hosted elsewhere) and it times out, this tells > me that there is a device in the middle someplace that is firewalling > the packets. > > you are *unlikely* to convince shaw to make firewall changes (if that is > what is happening) so you can do this. > > ok.. now the hopefully easy question :): why are you trying to set > things up this way? > > regards, > J > -- > Jeff MacDonald > Zoid Technologies, http://zoidtechnologies.com/ Fair question. I'll tell you what I'm trying to do, and perhaps you can advise a better solution. On my local machine I have a postpreSQL database. This database I update constantly let's say. Hosted on another machine in cyberspace is my webserver. On this machine I have a webpage that I want to update using data from the database on my local machine. The webserver is running PHP/mySQL. Can you think of a better way? A direct connection querying the database seemed like the best solution for this. I'm not sure if my web host would allow me to run a postgreSQL server on it as well. So, ftp'ing the database up once a day say may not be an option. One of my original thoughts (before I understood the systems at all) was that I would have to have a "cron" job running on my local machine that would ftp up data as it was collected. The webserver, the next time a php script ran, would check for new data, parse it, add it to the mySQL database on the webserver, and then run the scripts using the data from the webserver's mySQL server. Sounds horrid!
On Sat, 2006-02-04 at 23:24 -0500, vince@weaktight.com wrote: > Quoting Jeff MacDonald <jam@zoidtechnologies.com>: > > ok.. now the hopefully easy question :): why are you trying to set > > things up this way? > Fair question. I'll tell you what I'm trying to do, and perhaps you > can advise a better solution. > > On my local machine I have a postpreSQL database. This database I update > constantly let's say. > > Hosted on another machine in cyberspace is my webserver. On this machine I have > a webpage that I want to update using data from the database on my local > machine. The webserver is running PHP/mySQL. > > I'm not sure if my web host would allow me to run a postgreSQL server on it as > well. So, ftp'ing the database up once a day say may not be an option. > ask. if they say no, get an isp that will say yes. > One of my original thoughts (before I understood the systems at all) > was that I would have to have a "cron" job running on my local machine > that would ftp up data as it was collected. The webserver, the next > time a php script ran, would check for new data, parse it, add it to > the mySQL database on the webserver, and then run the scripts using > the data from the webserver's mySQL server. > have you considered SOAP? as much as I "love" mySQL, it does work (most of the time ;)) and with SOAP you can still update your data fairly often. regards, J -- Jeff MacDonald Zoid Technologies, http://zoidtechnologies.com/
Quoting Jeff MacDonald <jam@zoidtechnologies.com>: >> I'm not sure if my web host would allow me to run a postgreSQL >> server on it as >> well. So, ftp'ing the database up once a day say may not be an option. > > ask. if they say no, get an isp that will say yes. > >> One of my original thoughts (before I understood the systems at all) >> was that I would have to have a "cron" job running on my local machine >> that would ftp up data as it was collected. The webserver, the next >> time a php script ran, would check for new data, parse it, add it to >> the mySQL database on the webserver, and then run the scripts using >> the data from the webserver's mySQL server. > > have you considered SOAP? as much as I "love" mySQL, it does work (most > of the time ;)) and with SOAP you can still update your data fairly > often. > > regards, > J > -- > Jeff MacDonald > Zoid Technologies, http://zoidtechnologies.com/ I am still on a 30 day trial with their hosting, but I'm new to web development, so I'm slow to code up the things I want and wasn't sure what I needed going into this... I'm not quite sure what role SOAP would play in the desired system, but I'll look into it. Thanks for your help, Vince. Another technology to learn!
At 05:14 PM 2/4/06, vince@weaktight.com wrote: >I'm running PHP/mySQL via a web hosting service. I require my PHP scripts to >access an external PostgreSQL database. > >I have the PostgreSQL server setup to accept connections from anyone: >I've tested this connection via pgAdminIII and I'm able to connect using this >IP, but when I try to connect via php from the hosted webpage... > >But I'm foiled by: > >Warning: pg_connect(): Unable to connect to PostgreSQL server: could not >connect >to server: Operation timed out Is the server running on host >"24.85.82.xxx" and >accepting TCP/IP connections on port 5432? in >/usr/local/psa/home/vhosts/weaktight.com/httpdocs/mytest.php on line 13 > >Any thoughts or suggestions would be greatly appreciated. I'm not very >experienced with any of this stuff. Your webhosting company must be blocking outgoing requests on port 5432. I was able to connect to your server with your code - no problem.