ryeguy
ryeguy

Reputation: 66851

pg_connect crashes my php script

I'm trying to run a PHP script which has pg_connect($connection_string) and it just crashes my PHP script. I'm running it off of xampp on my computer, here are some facts:

And "connection failed" is never even displayed. My browser just shows "this page cannot be displayed",after timing out.

What in the world could be causing this?

Upvotes: 2

Views: 1939

Answers (6)

JWHerrle
JWHerrle

Reputation: 1

For me, the Apache logs revealed that PHP was not finding the pg_connect() function, even though php-postgresql was installed. Restarting Apache fixed this, i.e.

sudo service httpd restart

Upvotes: 0

user185958
user185958

Reputation:

sslmode=disable did the trick for me. To disable ssl in postgres-config ( ssl = false ) also worked.

Upvotes: 0

Fat Lotus
Fat Lotus

Reputation: 301

This sounds really stupid, but is your server running under SSL? I've had problems where a server will try to authenticate to ssl and hang indefinitely, trying to connect to a non-existent port.

Upvotes: 0

ryeguy
ryeguy

Reputation: 66851

Here it is guys: I have no reason why, but adding sslmode=disable to the end of my connection string made it work. What reason would it have to crash? I am on a windows machine and phpinfo() says OpenSSL is enabled..

Upvotes: 0

Byron Whitlock
Byron Whitlock

Reputation: 53871

  • Check the Apache error logs
  • Check the php error logs
  • Make sure you have logging enabled in your Postgres config file.
  • In your config, set

    log_min_error_statement (DEBUG5) 
    

    to grab everything possible.

  • Check the postgres error logs

Upvotes: 0

Randy
Randy

Reputation: 4023

It's doubtful that the call is crashing PHP. More likely is that for some reason, the call is hanging for some reason and PHP's max execution time is being exceeded. You can try extending the time limit before making the pg_connect() call to see if it eventually comes back with something.

Upvotes: 1

Related Questions