Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Persistent Connection Question WAS: SELECT LAST_INSERT_ID() keeps returning 0 AHHHH!!
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 th
e
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

Report this thread to moderator Post Follow-up to this message
Old Post
Andy Hassall
04-16-05 08:56 PM


Re: Persistent Connection Question WAS: SELECT LAST_INSERT_ID() keeps returning 0 AHHHH!!
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

Report this thread to moderator Post Follow-up to this message
Old Post
Andy Hassall
04-17-05 01:55 AM


Re: Persistent Connection Question WAS: SELECT LAST_INSERT_ID() keeps returning 0 AHHHH!!
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 requ
est
(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 anyth
ing
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

Report this thread to moderator Post Follow-up to this message
Old Post
Andy Hassall
04-17-05 01:55 AM


Re: Persistent Connection Question WAS: SELECT LAST_INSERT_ID() keeps returning 0 AHHHH!!
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 requ
est
(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 anyth
ing
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

Report this thread to moderator Post Follow-up to this message
Old Post
Andy Hassall
04-23-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:14 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.