You are here: Re: application level database connection « PHP Programming Language « IT news, forums, messages
Re: application level database connection

Posted by Erwin Moller on 11/17/06 09:25

rich wrote:

>
> Erwin Moller wrote:
>> Hi,
>>
>> I understood that if:
>> - the same login-credentials (username/password)
>> - from the same host
>> are used in your scripts, the connection will be recycled if you use
>> mysql_pconnect().
>>
>> Are you using pconnect?
>>
>
> No, I'm not. I think my biggest problem here that I don't fully
> understand is how can I (or is it possible to) use a resource for
> multiple instances of an object.


Hi,

I think you ONLY have to use mysql_pconnect instead of mysql_connect. PHP
will make sure the same connection isn't used at the same time.
I am not sure how it is implemented, but I expect PHP flags a connection
idle/finished when the script ends, but leaves the connection open, so next
time you need it you won't have to go through the authorisation again.

I understand that something like a
> static object will live throughout an object and it's children. But if
> 5 different processes open 5 different instances of the same object, is
> it even possible in PHP to give them the same resource if they never
> know about each other?

Yes, that is possible. PHP will handle that, you don't have to worry about
it. PHP must use some connectionpoolingmechanism behind the scenes, but I
do not know HOW.
But from a coders point of view: When PHP needs a connection, it checks if
it has one already (for the same user/password/host):
- If No, it creates a fresh one
- If yes (AND it is free), it returns that connection.


I suppose if what you say about pconnect is
> true, then you just answered my question.
>
> Thanks for the other tips on indexing too.. that'll definitely help.

First check the pconnect, if that doesn't help enough, redesign your
database since that will be a lot more work than adding a 'p' to your
script :-).
Long tables with indexes get very slow for inserts/updates.
Indexes only speed things up when querying (SELECT), but slow down
update/insert instructions.

Good luck!

Regards,
Erwin Moller

 

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

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