|
Posted by Erwin Moller on 11/17/06 12:10
Jerry Stuckle wrote:
> Erwin Moller wrote:
>> 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
>
> This will only make the situation worse.
Will it?
You sound very sure.
>
> Right now he has a problem with the maximum number of connections being
> occasionally exceeded. mysql_pconnect() requires the maximum number of
> connections to be allocated ALL the time.
That depends.
If the time it takes to run 1 request is short, then a relatively large
amount of time is spend on creating a connection.
If the script runs long, this is relatively short.
In the first case it might help to use pconnect().
But you knew that because you describe it yourself.
So why say it will make the situation worse?
The OP doesn't have to redesign his whole app or something.
It is easily checked with minimum effort.
I think it it definitely worth a try to add the 'p' and see if things run
smoother.
Regards,
Erwin Moller
>
> I have yet to see where mysql_pconnect SOLVES a problem. Normally it
> creates MORE. Yes, it's theoretically possible for it to help on very
> busy systems where connections are used for a very short time. But
> that's not the case here.
>
Navigation:
[Reply to this message]
|