Re: Why persistent connection ?
| From: | Chris Adams | Date: | Thu, 06 Jul 2000 01:55:09 +0000 |
| Subject: | Re: Why persistent connection ? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-885@lists.php.net to get a copy of this message | ||
> What's the advantage/utility/reason to use persistent
> connections instead of simple connections (in
If you have PHP running as a CGI or are not using persistent connections,
the life of your script looks like this:
- PHP starts script executing
- script connects to database
- script does little bit of work user actually cares about
- script disconnects from database
- PHP finishes execution
If you use persistent connections (which only work when PHP is a module),
it's like this:
- PHP starts script executing
- script does little bit of work user actually cares about
- PHP finishes execution
This can be a huge win if connecting to the database is a time consuming or
resource intensive operation. Depending on your script and configuration
details, this could require as much time as the rest of the script!
The reason for this is simple - most databases were designed around the
model of an application, where a user logs in when they get to work, runs a
ton of queries over the course of the day and logs out at the end of the
day. In this case, it makes a lot more sense to focus on making each query
fast and not worrying about the performance of establishing the connection.
Of course, with the web the performance model is completely different.
Without persistent connections, it's something like connect, run a couple
queries, disconnect, repeated many times. Persistent connections allow the
scripting engine to keep database connections open across many requests so
that your script won't need to connect to the database each time it's
called, which makes your script behave in a fashion more like what most
databases were designed to handle.