[nycphp-talk] When to close a mysql connection
Cliff Hirsch
cliff at pinestream.com
Mon Jul 2 10:11:20 EDT 2007
On 7/2/07 8:43 AM, "David Krings" <ramons at gmx.net> wrote:
> Cliff Hirsch wrote:
>> Hey, just an aside for everyone.
>>
>> I always had my DB close statement as the last line of my scripts. Then one
>> day, everything stopped working properly. Why?
>>
>> Seems right -- when you're done you're done -- right? Wrong. PHP does plenty
>> of "stuff" after your script is finished.
>>
>> Remember -- if you use database-base sessions, use session_write_close
>> BEFORE you close your DB connection. And you probably want to use
>> session_write_close before any header redirects as well to eliminate timing
>> issues.
>>
>> Cliff
>
> Thanks for pointing this out. I will add it to my scripts as I make
> frequent use of header redirects, they are just so effective.
>
> Although I should know if I use database-based sessions, I am not sure
> as I am not sure what exactly a database-based session is. So, what is that?
Standard PHP sessions are stored in flat files on the server. Not conducive
to scale-out as the session is local to a specific server, and there can be
security issues in a shared hosting environment. One alternative is to store
your sessionz in a database.
See: http://us.php.net/manual/en/function.session-set-save-handler.php
More information about the talk
mailing list