FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php and PDO Error HTTP 500
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
php and PDO Error HTTP 500 [message #179130] Fri, 14 September 2012 09:09 Go to next message
Une Bvue[1] is currently offline  Une Bvue[1]
Messages: 9
Registered: September 2012
Karma: 0
Junior Member
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.
Re: php and PDO Error HTTP 500 [message #179131 is a reply to message #179130] Fri, 14 September 2012 11:21 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
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???
Re: php and PDO Error HTTP 500 [message #179132 is a reply to message #179131] Fri, 14 September 2012 12:46 Go to previous messageGo to next message
Une Bvue[1] is currently offline  Une Bvue[1]
Messages: 9
Registered: September 2012
Karma: 0
Junior Member
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
Re: php and PDO Error HTTP 500 [message #179133 is a reply to message #179132] Fri, 14 September 2012 12:56 Go to previous messageGo to next message
Une Bvue[1] is currently offline  Une Bvue[1]
Messages: 9
Registered: September 2012
Karma: 0
Junior Member
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.
Re: php and PDO Error HTTP 500 [message #179134 is a reply to message #179132] Fri, 14 September 2012 13:35 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.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+connect ion+unexpectedly%22

HTH
Micha

--
http://mfesser.de/
Fotos | Blog | Flohmarkt
Re: php and PDO Error HTTP 500 [message #179138 is a reply to message #179132] Fri, 14 September 2012 14:36 Go to previous messageGo to next message
Allodoxaphobia is currently offline  Allodoxaphobia
Messages: 21
Registered: September 2010
Karma: 0
Junior Member
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
Re: php and PDO Error HTTP 500 [message #179139 is a reply to message #179134] Fri, 14 September 2012 15:29 Go to previous message
Une Bvue[1] is currently offline  Une Bvue[1]
Messages: 9
Registered: September 2012
Karma: 0
Junior Member
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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: log of all php's connection
Next Topic: How expensive is glob'ing a dir and including all the files?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Dec 03 17:39:26 GMT 2024

Total time taken to generate the page: 0.02077 seconds