one connection for many pages
Moderator: General Moderators
one connection for many pages
Is it possible to connect to database only once and use this connection across different pages ???
Re: one connection for many pages
infact it is the real waye to make a connectin on one page and include that page every where you need it,
make a separate page with dababase connction and
as per you requirements include or require php builtin functions would be used,
make a separate page with dababase connction and
as per you requirements include or require php builtin functions would be used,
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: one connection for many pages
I definitely wouldn't recommend using mysql_pconnect() unless you have a highly specific performance requirement to use it. Most of the time it will slow your connections down, because it doesn't really play well with Apache, and you'll end up with long lived mysql processes that aren't used and lots of new spawned processes occuring frequently.
Re: one connection for many pages
Hmm... I've never had those problems with it.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: one connection for many pages
Have you ever really looked at how it works, or carefully monitored your connections in a high traffic environment?Jade wrote:Hmm... I've never had those problems with it.
You will probably get away with it until you get lots of traffic.
Re: one connection for many pages
I get as many as 500 users during high traffic times and still no problems....but maybe that's not high enough traffic to cause an issue.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: one connection for many pages
And what about if you used normal mysql_connect(). Did you experience an issue with it?
Re: one connection for many pages
what exactly i want is there will be connection from one session and the same connection will be used across different page requests in the same session.. 
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: one connection for many pages
Resources cannot be serialized, so no, you cannot store the connection for reuse across multiple pages. If you want to keep the connection open, and can re-connect to the open connection, then use persistent connections (but I don't recommend it).lipun4u wrote:what exactly i want is there will be connection from one session and the same connection will be used across different page requests in the same session..
I just think your trying to solve a problem that doesn't exist. Just use mysql_connect() normally on each page request.