PHPBuilder: Custom Session Handlers in PHP4

Written By
Web Webster
Web Webster
Jun 2, 2000

[ Thanks to Kevin
Reichard
for this link. ]

This document describes how to customize the session
handlers in PHP4. We will provide examples of how to write a fully
functional session handler that works with DBM files and one that
works with a MySQL database.

“New to PHP4 was a set of native session handling functions
which was badly missing from PHP3. By default, each session is
stored as a separate file in your temporary directory (eg. /tmp in
Unix). This may or may not be appropriate depending on your
requirements. For example, if you have a bunch of web/PHP servers
on different machines, you can’t easily share sessions between them
(well you could save the sessions on an NFS share but that would be
slow). Another problem is that you potentially have thousands or
even millions of session files cluttering up your file system (you
run a big site right ).”

“Fortunately for us, the developers of PHP4 were forward
thinking enough (thanks!) to provide the ability for users like you
and me to extend the session handling routines.”

“This document is written to explain these session handlers a
bit and to provide two working examples of how you can extend the
session handlers. Our first example will be to make the session
handlers save session data into DBM files. Our second example will
have our sessions save into a MySQL database.”

Complete
Story

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.