PDA

View Full Version : Database connections and PHP sessions


tangosdad
06-27-2008, 10:43 PM
I'm new to PHP and so far I am loving it! A few questions:

1.) How should database connections be handled in terms of moving from page to page?

Is one database connection maintained throughout my application or do I close the connection as I leave one page (or is it done automatically) and then reconnect at the start of each page?

2.) Are database connections automatically killed when a page is closed or is there something special I need to do when someone logs off or closes the browser or surfs to another page?

3.) Same question with regards to php sessions. Anything special that I need to be doing with the php sessions?

Thanks!
Mark

davidj
06-28-2008, 12:57 AM
1.) How should database connections be handled in terms of moving from page to page?

Is one database connection maintained throughout my application or do I close the connection as I leave one page (or is it done automatically) and then reconnect at the start of each page?


the coonection is established when needed and then closed automatically.

2.) Are database connections automatically killed when a page is closed or is there something special I need to do when someone logs off or closes the browser or surfs to another page?

see above


3.) Same question with regards to php sessions. Anything special that I need to be doing with the php sessions?

nope

they expire on their own


taken from PHP.ini


; Define the probability that the 'garbage collection' process is started on every session initialization.
; The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request.


from php.ini

session.gc_probability = 1
session.gc_divisor = 1000

tangosdad
06-28-2008, 01:13 AM
Oh wow, that makes it easy. I was worried about nothing. Thanks!