Home > Archive > PHP Language > April 2005 > Re: Persistent Connection Question WAS: SELECT LAST_INSERT_ID() keeps returning 0 AHH
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Persistent Connection Question WAS: SELECT LAST_INSERT_ID() keeps returning 0 AHH
|
|
| Andy Hassall 2005-04-16, 3:56 pm |
| On Sat, 16 Apr 2005 11:32:29 -0600, Dumbass <blah@hotmail.com> wrote:
>Rizyak wrote:
>
>This provokes a question I have been pondering for quite some time but
>am unsure of how to test for an answer.
>
>I know that this wouldn't be an issue with a regular connection but
>using persistent connection suppose I have script.php and there are 2
>instances running.
>
>If I do an INSERT followed by mysql_insert_id() in instance1, but
>between those 2 statments instance2 does an INSERT, would this introduce
>a kind of race condition where instance1 would get the insert id of
>instance2?
>
>And the same thing with mysql_select_db(). If instance1 selects
>databaseA, and instance2 runs a SELECT statement thinking it is using
>databaseB wouldn't that cause an error?
I didn't think persistent connections were multiplexed; I thought they were
allocated to a request for the request's lifetime then released back into the
persistent connection pool. But looking at the source code I can't spot it
doing this - so possibly.
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
| |
| Andy Hassall 2005-04-16, 8:55 pm |
| On Sat, 16 Apr 2005 12:34:09 -0600, Dumbass <blah@hotmail.com> wrote:
>Andy Hassall wrote:
>
>But from what I understand persistent connections are allocated by
>host/user/pass, so assuming that the script only uses 1 host/user/pass
>combination wouldn't there only be 1 connection?
>
>Or is that the answer... if the script is initiated again and the 1
>resource is being used by instance1 it will create another connection,
>resulting 2 persistanct resources, in which case they would be seperate
>connections and would not suffer from this kind of race condition. That
>would make sense.
Yes, that's exactly the behaviour I was trying to say that I expected - but I
couldn't see any evidence of it checking whether the matching persistent
connection was currently in use before letting the current script use it.
Ah - I've just realised why this is fine. There will only be one instance of
PHP running at a given time - per apache worker process. The persistent
connection pool is itself per worker process, and so there is no way two
concurrent PHP instances can share the connection, since they'll be on
different processes.
I assume that for multi-threaded servers rather than multi-process servers
(i.e. IIS or apache on Windows), the connection pool is thread-local - if so,
then again it's safe.
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
| |
| Andy Hassall 2005-04-16, 8:55 pm |
| On Sat, 16 Apr 2005 14:05:39 -0600, Dumbass <blah@hotmail.com> wrote:
>So can we
>conclude from this that using a persistent connection with the cli or
>cgi SAPI's is pointless?
Yep.
http://www.php.net/manual/en/featur...connections.php
"The first method is to use PHP as a CGI "wrapper". When run this way, an
instance of the PHP interpreter is created and destroyed for every page request
(for a PHP page) to your web server. Because it is destroyed after every
request, any resources that it acquires (such as a link to an SQL database
server) are closed when it is destroyed. In this case, you do not gain anything
from trying to use persistent connections -- they simply don't persist."
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
| |
| Andy Hassall 2005-04-23, 3:56 am |
| On Sat, 16 Apr 2005 14:05:39 -0600, Dumbass <blah@hotmail.com> wrote:
>So can we
>conclude from this that using a persistent connection with the cli or
>cgi SAPI's is pointless?
Yep.
http://www.php.net/manual/en/featur...connections.php
"The first method is to use PHP as a CGI "wrapper". When run this way, an
instance of the PHP interpreter is created and destroyed for every page request
(for a PHP page) to your web server. Because it is destroyed after every
request, any resources that it acquires (such as a link to an SQL database
server) are closed when it is destroyed. In this case, you do not gain anything
from trying to use persistent connections -- they simply don't persist."
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
|
|
|
|
|