must i relate the link created with pconnect to some session id or
something?
No, you are confusing two meanings of persistence here. (As I tried
to explain earlier, but I'll try to do it better this time.) Please bear
in mind that I'm not reading the actual source code as I write this,
so treat it as a "virtual" explanation rather than being accurate in
all the details--the concepts are definitely correct.
Are you using Apache as a server? I'll assume so, since that is what
I'm familiar with; the details are different with IIS but not the concepts.
Apache uses a pre-forking model to enhance performance: it creates
a number of processes to handle http requests ahead of time. When
an incoming connection is received, the master httpd hands of the
request to one of the existing idle processes. If there are none, it
may create some more, but in the general case it finds an idle process
and thus the page request is handled without any process-creation
overheard.
So far so good. When you are using PHP via mod_php rather than
as a CGI, PHP itself is compiled into 'httpd', so these individual server
processes execute the php parsing and functionality again without
any process-creation overhead; this is what makes PHP as a module
perform so well.
Now we get to the database connections. connect() merely establishes
a connection to the database. When page exits (and the instance of
httpd goes back to idle, waiting for another request) the database
connection is dropped. If the very next page request that is handed
to this instance makes a connection to the same database via
connect(), it has to establish a connection to the database all over
again.
However, if pconnect() is used, the connection is not dropped when
the script exits. If the next call to pconnect() that is handled by
this instance of 'httpd' is for the same database using the same
userid as the last call, then the already-open connection is simply
used as is, without incurring the overhead of establishing the connection.
So you get a performance enhancement.
But it is VERY important to note that there is nothing else carried forward
between page requests to the same instance of 'httpd', and it's by no
means guaranteed (or, for all we know, even likely) that two successive
requests from the same client are going to be routed to the same instance
of 'httpd'. Therefore, at the level of your script, there is no persistence
between one page and the next: you still have to call pconnect() to
connect to the database each time you want to use it. And the individual
instance of httpd that handles this request has no knowledge of what
your previous request was, or anything about the results of it.
Does this help clarify things?