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

Persistent Connection Question
Hello all,

Sorry if you are getting this twice I am not sure if my other one
actually made it or not.

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?

TIA,
Me

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


Re: Persistent Connection Question
"Dumbass" <blah@hotmail.com> wrote in message
news:1162l1sa3pujo12@corp.supernews.com...
> Hello all,
>
> Sorry if you are getting this twice I am not sure if my other one
> actually made it or not.
>
> 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?
>
> TIA,
> Me

The answers to your questions are 'no', each instance will receive the
insert id associated with its connection id and neither will trip up over
which database the other is currently accessing...

Norm
--
FREE Avatar hosting at www.easyavatar.com



Report this thread to moderator Post Follow-up to this message
Old Post
Norman Peelman
04-17-05 08:57 AM


Re: Persistent Connection Question
Norman Peelman wrote:
> "Dumbass" <blah@hotmail.com> wrote in message
> news:1162l1sa3pujo12@corp.supernews.com...
> 
>
>
> The answers to your questions are 'no', each instance will receive the
> insert id associated with its connection id and neither will trip up over
> which database the other is currently accessing...
>
> Norm

And how do you know this?

Report this thread to moderator Post Follow-up to this message
Old Post
Dumbass
04-17-05 08:57 AM


Re: Persistent Connection Question
In article <1163lqvahdrvt6f@corp.supernews.com>,
Dumbass <blah@hotmail.com> wrote:

> Norman Peelman wrote: 
>
> And how do you know this?

Simple.  It's the way connections to MySQL are created by PHP.  You can
download the source to PHP and MySQL and check for yourself.

--
DeeDee, don't press that button!  DeeDee!  NO!  Dee...




Report this thread to moderator Post Follow-up to this message
Old Post
Michael Vilain
04-17-05 01:56 PM


Re: Persistent Connection Question
Michael Vilain wrote:
> Simple.  It's the way connections to MySQL are created by PHP.  You can
> download the source to PHP and MySQL and check for yourself.
>

What kind of answers are those though? "No", "Simple. That's the way it
is!" Have you read the source and understand how it works? If so then
why didn't you offer an explanation? Not all of us are end user level
programmers. Some of us can take a little technical discussion. And
explanation like this would have been nice...

Persistent resources are per engine. For example, with apache 1.3.x and
apache2-prefork mpm, there is one php engine per child. Each engine has
it's own persistant resource list. So a script running with 2 instances
do not share a single resource. They each use the persistent connection
for that instance of the engine. Also because of this there is no such
thing as persistent resources for the cli or cgi SAPI's (even if the cgi
is ran thru apache) because the engine is created and destroyed for each
request, so "the persistent connections simply do no persist".

Report this thread to moderator Post Follow-up to this message
Old Post
Dumbass
04-17-05 08:55 PM


Re: Persistent Connection Question
Dumbass wrote:

> Michael Vilain wrote: 
>
> What kind of answers are those though? "No", "Simple. That's the way it
> is!" Have you read the source and understand how it works? If so then
> why didn't you offer an explanation? Not all of us are end user level
> programmers. Some of us can take a little technical discussion. And
> explanation like this would have been nice...
>

No need to loose the plot - Michael is trying to help to help you here.

And the answer is perfectly valid.

And a much better answer than 'because the supplier said so'.

If you can't be bothered to check the source for yourself but *must* know
the answer, TEST IT YOURSELF.

C.

Report this thread to moderator Post Follow-up to this message
Old Post
Colin McKinnon
04-18-05 01:55 PM


Re: Persistent Connection Question
> What kind of answers are those though? "No", "Simple. That's the way it
> is!" Have you read the source and understand how it works? If so then
> why didn't you offer an explanation? Not all of us are end user level
> programmers. Some of us can take a little technical discussion. And
> explanation like this would have been nice...

Rather than getting nasty at each other ...

When the poster means two instances running, I assume it is meant that the
script is called simultaneously by to "users" as opposed to simultaneously
(sort of) by the same calling program, i.e. same user. I think mysql and
php are able to handle this without getting ; that is the whole
point of persistant connections, otherwise why bother implementing it?
Without knowing any of the details, I assume a connection ID is
established for each connection, and it is this ID that is used to
determine stuff like last_insert etc.



Report this thread to moderator Post Follow-up to this message
Old Post
coolsti
04-18-05 01:55 PM


Re: Persistent Connection Question
"Dumbass" <blah@hotmail.com> wrote in message
news:1163lqvahdrvt6f@corp.supernews.com...
> Norman Peelman wrote: 
over 
>
> And how do you know this?

Because I use PHP/MySQL and I learned, read the docs/manuals/faqs/etc.
Bottom line, test it for yourself (as has been suggested) - don't confuse
the database connection with the php resource identifier.

Norm
--
FREE Avatar hosting at www.easyavatar.com



Report this thread to moderator Post Follow-up to this message
Old Post
Norman Peelman
04-18-05 01:55 PM


Re: Persistent Connection Question
"Dumbass" <blah@hotmail.com> wrote in message
news:1163lqvahdrvt6f@corp.supernews.com...
> Norman Peelman wrote: 
over 
>
> And how do you know this?

Because I use PHP/MySQL and I learned, read the docs/manuals/faqs/etc.
Bottom line, test it for yourself (as has been suggested) - don't confuse
the database connection with the php resource identifier.

Norm
--
FREE Avatar hosting at www.easyavatar.com



Report this thread to moderator Post Follow-up to this message
Old Post
Norman Peelman
04-20-05 01:55 PM


Re: Persistent Connection Question
Michael Vilain wrote:
> Simple.  It's the way connections to MySQL are created by PHP.  You can
> download the source to PHP and MySQL and check for yourself.
>

What kind of answers are those though? "No", "Simple. That's the way it
is!" Have you read the source and understand how it works? If so then
why didn't you offer an explanation? Not all of us are end user level
programmers. Some of us can take a little technical discussion. And
explanation like this would have been nice...

Persistent resources are per engine. For example, with apache 1.3.x and
apache2-prefork mpm, there is one php engine per child. Each engine has
it's own persistant resource list. So a script running with 2 instances
do not share a single resource. They each use the persistent connection
for that instance of the engine. Also because of this there is no such
thing as persistent resources for the cli or cgi SAPI's (even if the cgi
is ran thru apache) because the engine is created and destroyed for each
request, so "the persistent connections simply do no persist".

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


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
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:15 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.