Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

php and PDO Error HTTP 500

801 views
Skip to first unread message

Une Bévue

unread,
Sep 14, 2012, 5:09:56 AM9/14/12
to
I get this http error 500 within a page when i want to connect to a
postgresql database.
This database is working well in command line ($ psql ...)

Although i got an error message using the php script :
yt@D620 /home/yt/Sites/yt_tests $ php index.php

PHP Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[08006] [7] server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.' in
/home/yt/Sites/yt_tests/index.php:75
Stack trace:
#0 /home/yt/Sites/yt_tests/index.php(75):
PDO->__construct('pgsql:dbname=yt...', 'yt', 'yvon5533')
#1 {main}
thrown in /home/yt/Sites/yt_tests/index.php on line 75
zsh: exit 255 php index.php

line 75 being :
$db = new PDO("pgsql:dbname=$dbname;host=$host;", $username, $password );

i do not got any php error when connecting thru a browser.

everything is installed for PDO / PostgreSQL following my info.php page :
Additional .ini files parsed /etc/php5/apache2/conf.d/curl.ini,
/etc/php5/apache2/conf.d/pdo.ini,
/etc/php5/apache2/conf.d/pdo_pgsql.ini,
/etc/php5/apache2/conf.d/pgsql.ini, /etc/php5/apache2/conf.d/xsl.ini

PDO

PDO support enabled
PDO drivers pgsql

pdo_pgsql

PDO Driver for PostgreSQL enabled
PostgreSQL(libpq) Version 9.1.5
Module version 1.0.2
Revision $Id: pdo_pgsql.c 321634 2012-01-01 13:15:04Z felipe $

pgsql

PostgreSQL Support enabled
PostgreSQL(libpq) Version 9.1.5
Multibyte character support enabled
SSL support enabled
Active Persistent Links 0
Active Links 0

Directive Local Value Master Value
pgsql.allow_persistent On On
pgsql.auto_reset_persistent Off Off
pgsql.ignore_notice Off Off
pgsql.log_notice Off Off
pgsql.max_links Unlimited Unlimited
pgsql.max_persistent Unlimited Unlimited


I don't undertand this prob.

Captain Paralytic

unread,
Sep 14, 2012, 7:21:00 AM9/14/12
to
On Sep 14, 10:09 am, Une Bévue <unbewusst.s...@fai.invalid> wrote:
> I get this http error 500 within a page when i want to connect to a
> postgresql database.
A "page" is what is displayed in a browser.

> i do not got any php error when connecting thru a browser.
This contradicts what you said above.

Can you please explain???

Une Bévue

unread,
Sep 14, 2012, 8:46:27 AM9/14/12
to
Le 14/09/2012 13:21, Captain Paralytic a �crit :
> A "page" is what is displayed in a browser.

yes, of course, i did two trials :
- connecting to the php script thru a browser (ie.
http://localhost/yt_tests/index.php);
- executing the php script from CLI (Command Line Interface).

I did the latest because i got an HTTP error 500 when using a browser.
The second way gave more information about what is going on.

>> >i do not got any php error when connecting thru a browser.
> This contradicts what you said above.
> Can you please explain???

I do not get any PHP error rather a "HTTP 500 (Internal Server Error)"
even if all of the PHP reporting error are allowed in my php setup files:
error_reporting = E_ERROR & E_WARNING & E_PARSE & E_NOTICE &
E_CORE_ERROR & E_CORE_WARNING & E_COMPILE_ERROR & E_COMPILE_WARNING &
E_USER_ERROR & E_USER_WARNING & E_USER_NOTICE & E_RECOVERABLE_ERROR &
E_USER_DEPRECATED ;

And, the only php line raising an error is this one :
$db = new PDO("pgsql:dbname=$dbname;host=$host;", $username, $password );

I know that because commenting it suppress the "HTTP 500 (Internal
Server Error)".

Also, this script was working well two months ago, before my hard disk
crashed. After this crash i did rebuild all of my linux (Xubuntu /
Voyager 12.04 LTS) the same way i did it in april.

Also i sohould say i can connect to this database without any prob from
CLI that way :
$ psql -h <IPV4 or IPV6 of the server> -U yt -d yt_tests


Une Bévue

unread,
Sep 14, 2012, 8:56:45 AM9/14/12
to
Le 14/09/2012 14:46, Une B�vue a �crit :
>
> Also i sohould say i can connect to this database without any prob from
> CLI that way :
> $ psql -h <IPV4 or IPV6 of the server> -U yt -d yt_tests
I should also mention that the prob arroses only on this linux
computer. Using the "same" script (changing only $hostname="localhost";
to the IPV6 of another computer having the same database) works as expected.

Michael Fesser

unread,
Sep 14, 2012, 9:35:12 AM9/14/12
to
.oO(Une B�vue)

>I did the latest because i got an HTTP error 500 when using a browser.
>The second way gave more information about what is going on.

A general note: In case of a HTTP 500 error look at the server's error
log file, usually you find an explanation there what caused the crash.

In this case it's quite possible that you'll find the same error message
there or at least a note about the PHP interpreter crashing because of
the exception.

>I do not get any PHP error rather a "HTTP 500 (Internal Server Error)"
>even if all of the PHP reporting error are allowed in my php setup files:
>error_reporting = E_ERROR & E_WARNING & E_PARSE & E_NOTICE &
>E_CORE_ERROR & E_CORE_WARNING & E_COMPILE_ERROR & E_COMPILE_WARNING &
>E_USER_ERROR & E_USER_WARNING & E_USER_NOTICE & E_RECOVERABLE_ERROR &
>E_USER_DEPRECATED ;

When the interpreter crashes and the server responds with HTTP 500,
there's no way for PHP to show you the error message. You have to look
at the log files instead.

>Also, this script was working well two months ago, before my hard disk
>crashed. After this crash i did rebuild all of my linux (Xubuntu /
>Voyager 12.04 LTS) the same way i did it in april.

Often it helps to search on Google or any other SE for the error
message. In this case there are some results, some of them indicate a
problem when using a persistent connection to the database:

https://www.google.com/search?q=PDO+postgresql+%22server+closed+the+connection+unexpectedly%22

HTH
Micha

--
http://mfesser.de/
Fotos | Blog | Flohmarkt

Allodoxaphobia

unread,
Sep 14, 2012, 10:36:00 AM9/14/12
to
On Fri, 14 Sep 2012 14:46:27 +0200, Une B�vue wrote:
> Le 14/09/2012 13:21, Captain Paralytic a �crit :
>> A "page" is what is displayed in a browser.
>
> yes, of course, i did two trials :
> - connecting to the php script thru a browser (ie.
> http://localhost/yt_tests/index.php);
> - executing the php script from CLI (Command Line Interface).
>
> I did the latest because i got an HTTP error 500 when using a browser.
> The second way gave more information about what is going on.

AFAIK, server PHP and CLI PHP run under two different php.ini configs.
Could be the problem.

Jonesy

Une Bévue

unread,
Sep 14, 2012, 11:29:01 AM9/14/12
to
Le 14/09/2012 15:35, Michael Fesser a �crit :
> A general note: In case of a HTTP 500 error look at the server's error
> log file, usually you find an explanation there what caused the crash.
>

I've found nothing in the PostgreSQL log and, in apache2 error log i've
found the same message as i get using Command Line Interface :
$ php index.php.

>
>> >I do not get any PHP error rather a "HTTP 500 (Internal Server Error)"
>> >even if all of the PHP reporting error are allowed in my php setup files:
>> >error_reporting = E_ERROR & E_WARNING & E_PARSE & E_NOTICE &
>> >E_CORE_ERROR & E_CORE_WARNING & E_COMPILE_ERROR & E_COMPILE_WARNING &
>> >E_USER_ERROR & E_USER_WARNING & E_USER_NOTICE & E_RECOVERABLE_ERROR &
>> >E_USER_DEPRECATED ;
> When the interpreter crashes and the server responds with HTTP 500,
> there's no way for PHP to show you the error message. You have to look
> at the log files instead.

OK, fine thanks.

>> >Also, this script was working well two months ago, before my hard disk
>> >crashed. After this crash i did rebuild all of my linux (Xubuntu /
>> >Voyager 12.04 LTS) the same way i did it in april.
> Often it helps to search on Google or any other SE for the error
> message. In this case there are some results, some of them indicate a
> problem when using a persistent connection to the database:

I've added :
array( PDO::ATTR_PERSISTENT => false)
to :
$db = new PDO( "pgsql:dbname=$dbname;host=$host;",
$username,
$password,
array( PDO::ATTR_PERSISTENT => false)
);

no change at all.

0 new messages