Join David Powers for an in-depth discussion in this video Closing the session and garbage collection, part of Managing PHP Persistent Sessions.
- We've added the code to the Mysql…SessionHandler class to open,…read, and write session data.…Next we need to deal with the close and gc methods.…Close is self-explanatory.…Gc performs garbage collection,…deleting session data that's out of date.…The code for the gc method is very simple.…So let's tackle that first.…Let's just scroll down to find the signature for gc.…There it is.…It takes a single parameter, maxlifetime.…It gets this value automatically…from the session gc maxlifetime directive…in the server's configuration.…
The default is 1,440 seconds or 24 minutes.…Garbage collection isn't performed…every time a session starts.…PHP uses random probability,…but it rolls the dice, as it were,…at the start of the session.…Deleting out of date records…at the beginning of the session…could slow down a busy site.…So we'll delay garbage collection…and incorporate it into the close method.…So all we need to do here in between…the curly braces is to set the collectGarbage…property to true.…
So this collectGarbage…= true,…
- Configuring sessions
- Inspecting how session data is stored
- Implementing persistent sessions
- Creating a SQL database to store session data
- Implementing the PHP SessionHandlerInterface
- Writing session data
- Closing and destroying sessions
- Creating an auto-login system with persistent sessions
- Creating persistent logins
- Checking out visitor credentials
- Authenticating users
- Logging out users selectively
Skill Level Intermediate
Accessing Databases with Object-Oriented PHPwith David Powers3h 47m Intermediate
1. Sessions and Security
2. Preparing the Database
Connecting to the database5m 49s
3. Storing Session Data in MySQL
4. Creating an Autologin System
5. Testing the Autologin System
Final thoughts3m 9s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.