简体   繁体   English

在PHP中使用pg_connect()的错误500(致命错误)

[英]Error 500 ( Fatal Error ) using pg_connect() in php

im trying to use pg_connect to access postgres on another server,, 我试图使用pg_connect来访问另一台服务器上的postgres,

i did opened the remote access and i can use bash to connect to my postgres server ! 我确实打开了远程访问,并且可以使用bash连接到我的postgres服务器! and i did host all all client_ip/32 trust in config but when im trying to use pg_connect i get error 500 ! 而且我确实在配置中托管了所有所有client_ip / 32信任,但是当我尝试使用pg_connect出现错误500! pgsql is also installed and i've checked it with function_exists('pg_connect') and i returns true ! pgsql也已安装,我已经用function_exists('pg_connect')进行了检查,并且我返回true! my code is : 我的代码是:

$dbconn = pg_connect("host=remote_IP port=5432 dbname=myDB user=postgres") or die("Could not connect");

i've also tried this and get fatal error 500 again 我也尝试过这个,再次出现致命错误500

    $dbconn = pg_connect("host=remote_IP port=5432 dbname=myDB
 user=another_super_user_i_made password=user_password") or die("Could not connect");

what is the problem ? 问题是什么 ?

when you are able to connect to a server from one machine on your network, but get a connection timed out issue from another machine, it usually is due to one of a few things. 当您能够从网络上的一台计算机连接到服务器,但又从另一台计算机获得连接超时问题时,通常是由于以下原因之一。

1) DNS. 1)DNS。 The machine you are testing from (the "remote access" as you call it) is able to resolve the DNS name and the webserver running your PHP code is not. 您要测试的计算机(称为“远程访问”)能够解析DNS名称,而运行PHP代码的网络服务器则无法解析。 You can use actual IP address instead of DNS names to test this. 您可以使用实际的IP地址代替DNS名称来进行测试。

2) Connectivity. 2)连接。 Different machines are connected in different ways in a network. 网络中不同的计算机以不同的方式连接。 If you are able to get to an IP from the "remote access" machine but the web server is having trouble connecting to it (with "connection timed out"), try connecting directly to that web server (using "remote access" like SSH) and see if you can connect manually from there. 如果您可以从“远程访问”计算机获取IP,但是Web服务器无法连接到该IP(“连接超时”),请尝试直接连接到该Web服务器(使用像SSH这样的“远程访问” ),看看是否可以从那里手动连接。

If it's not a network related issue it could be an issue with your default PG timeouts. 如果不是与网络相关的问题,则可能是您的默认PG超时问题。 Try setting them manually with the connect string. 尝试使用连接字符串手动设置它们。 Specifically, the "connect_timeout" option, like this: 具体来说,“ connect_timeout”选项如下所示:

$d=pg_connect('host=example.com user=pgsql dbname=postgres connect_timeout=5');

There was host blocking issue ! 出现主机阻止问题! my client hosting was not enabling remote access to DB ! 我的客户端托管未启用对DB的远程访问! you should check with your hosting that they can trace your problem 您应该向您的主机咨询以确保他们可以跟踪您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM