NYCPHP Meetup

NYPHP.org

[nycphp-talk] mysql_close() error

Matthew Terenzio webmaster at localnotion.com
Wed Dec 22 17:10:28 EST 2004


On Dec 21, 2004, at 9:46 PM, Frank Wong wrote:

>
> Adam Maccabee Trachtenberg  wrote:
>
>> I believe that if you try to make a second connection to MySQL via PHP
>> that's identical to an existing connection, then PHP will reuse the
>> first connection. That's why mysql_connect() returns the same resource
>> handle.
>
> Which would explain why $link loses its magical resourceness after the
> first mysql_close() -- and also why it's a good idea not to use
> mysql_close(), except in exceptional circumstances.

I wasn't paying terribly close attention to this thread but I had an 
issue today which may be related.

Using Postgresql, I recently added a couple of scripts written by an 
outside company which allowed them to bulk sync some data that my 
company wanted.

I began noticing that some of my DB backed web pages were displaying 
errors .
Shame on me for allowing that, I know, I hadn't read Phundamentals yet 
when I created those pages :)
Any way. . .

The two errors were Postgres "can't connect, too many clients already."

and Postgres "The connection was terminated by the administrator"

The latter being caused mostly by a page refresh.

I upped the Postgresql.conf max users to 64 instead of 32 though I knew 
that was not a proper fix.
I suspected these scripts so I removed them.
The errors continued but at a lesser and lesser rate. I guessed some 
connections were still actively being shared.
Finally they ceased.

I looked at the scripts again and they were pretty basic, but I changed 
pg_connect()  to pg_pconnect() and removed the pg_close() altogether.

So far so good. Time will tell.

I guess the moral is don't let cold fusion guys write your PHP scripts. 
:)
I didn't just throw the scripts on the server, by the way, but they 
were pretty basic and it didn't occur to me that the close DB function 
would terminate connections elsewhere.

That is what happened isn't it?




More information about the talk mailing list