tags:

views:

219

answers:

5

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:

  • If I put exit("test"); immediately above the pg_connect statement, it successfully displays the word "test" and terminates the script, so I know that my installation of xampp is working.
  • Using phpinfo() I can see that the postgresql extension is indeed loaded.
  • I can connect to the database server from pgadmin, so it's not a firewall issue or anything like that.
  • If I remove this exit statement, the pg_connect statement just hangs. There is no warning displayed or logged, and it never even gets past the function call. I even have:

    $db_crm = pg_connect($connection_str);

    if (!$db_crm) die("connection failed");

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?

+1  A: 

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.

Randy
A: 
  • 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
Byron Whitlock
A: 

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..

ryeguy
A: 

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.

Fat Lotus
I'm assuming it is. The original code did not have that property set in the connection flag. However, the original code is running on linux while when this problem occurred I was under windows.
ryeguy
A: 

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

shel