You are here: Re: Two mysql connections « PHP Programming Language « IT news, forums, messages
Re: Two mysql connections

Posted by Gordon Burditt on 06/14/06 00:14

>Not really tried going two ways at once, but I have an include_once
>connection to a mysql_database, now I need to retrieve info from a second
>mysql_database ..

Connections aren't include_once. You may be including the code to make
the connection with include_once, but that doesn't affect the connection.

>My mysql_connects are getting confused. So, (I've had a couple of beers), am
>I opening up too many at once?

No. I had a page that opened up 3 connections (in this case, on 3
different servers) to compare the data on the 3 servers. Essentially,
it was a test for a data migration script (which also involved a
lot of reorganization) to check if anything got missed. It proved
very useful. Performance and simultaneous use weren't issues, and
only I used it.

You should pass the correct connection handle (er, "resource") to
all of the mysql_* functions to indicate which one you wish to use,
including mysql_query, mysql_select_db, and functions to fetch
results. If you don't pass the connection handle, PHP will pick
one (I forget whether it's the first or the latest), and Murphy's
law says it gets the wrong one more than 50% of the time.

>I'll look again in the morning, but am thinking that it is a bad idea to
>leave two connections open all the time ...

Leaving two connections open during processing a PHP page is not
"all the time" unless you've got a heck of a lot of traffic.

Persistent connections tend to accumulate a large number of idle
connections, perhaps more than the server can handle. You also
tend to end up with the MAXIMUM number of connections (as set in
Apache by child_max) rather than the average number of simultaneous
connections actually being used).

Assuming, for the moment, that generating the PHP page takes less
than, say, 1 minute, you should hold the connections for as long
as you need them rather than disconnecting and re-connecting. That's
probably the whole time unless you are doing complicated manipulation
of the data after you fetch it before presenting it. If it takes
longer than that, how do you put up with that poor response?

Gordon L. Burditt

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация