Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 101743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:49:47+00:00 2026-05-11T00:49:47+00:00

When it comes to writing custom MySQL database-driven PHP session management for a VERY

  • 0

When it comes to writing custom MySQL database-driven PHP session management for a VERY dynamic website, what is the best (fastest read/write access) structure for your session table?

Bad Example (Not Optimized):

 CREATE TABLE `session` (     `session_id` VARCHAR(32) NOT NULL,     `session_data` TEXT NOT NULL,     `t_created` DATETIME NOT NULL,     `t_updated` DATETIME NOT NULL,     PRIMARY KEY  (`session_id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; 

I assume that using the Memory Engine would be better/faster, but I’m not sure. I can’t think of a good way to explain everything in English, so I’ve made a list of requirements/details that I think are important:

Details:

  • Category: Optimization
  • Sub Category: MySQL Query Performance
  • Goal: Fastest Random Access Table Schema and Single Row Query
  • Common Uses: Custom Session Management, Temporary Storage
  • Operating System: *nix, more specifically: Centos 5+ (on x86_64)
  • Database: MySQL Version: 5+ (Community Version)

Outcomes:

  • SQL Query: Create Table
  • SQL Query: Select Single Row by Random Key (e.g. PHP session id)
  • SQL Query: Insert Single Row with Random Key (e.g. PHP session id)
  • SQL Query: Update Single Row by Random Key (e.g. session id)
  • SQL Query: Delete Multiple Rows by Timestamp (garbage collection, e.g. expired sessions)

Expected Row Lifespan (e.g. session durations):

  • 30%: 0s-30s
  • 20%: 30s-5m
  • 30%: 5m-1h
  • 20%: 1h-8h

Expected Row Count (e.g. active sessions):

  • Low: 128
  • Medium: 1024
  • High: 100000

If anyone can think of a better way to phrase all this, please feel free to edit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:49:48+00:00Added an answer on May 11, 2026 at 12:49 am

    Your intuition seems to be about right. I’d recommend creating the table as follows:

    CREATE TABLE session (   id CHAR(32) NOT NULL,   data BLOB NOT NULL,   t_created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,   t_updated TIMESTAMP,   PRIMARY KEY (session_id),   INDEX t_created(t_created),   INDEX t_updated(t_updated) ) ENGINE = MEMORY CHARACTER SET utf8; 

    Notes:

    • id – CHAR is less expensive when you know the length of the contents
    • data – BLOB (Binary Large OBject) is more applicable here, as you’re likely storing something other than TEXT.
    • t_created and t_updated – TIMESTAMP – calculations are faster, although you’re limited to the time range 1901-2038 but that should be fine for this application.
    • INDEXes on t_created and t_updated are memory expensive and not entirely necessary, but they can really help performance when querying by these columns.
    • MEMORY tables, while incredibly fast, have their limitations. If your mysqld relaunches, all data is lost.

    Side note: I’m not sure how you plan to garbage-collect your sessions, but if you’re expecting 50% of your sessions to be under 5 minutes, how is an end-of-session defined? Must a user/client explicitly end their session (via logging out)? If you implicitly end sessions that quickly, your users may have a very rough time with your website.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 98k
  • Answers 98k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ok, found the answer. I tried something that I didn't… May 11, 2026 at 7:32 pm
  • Editorial Team
    Editorial Team added an answer I got a wee-bit curious -- some older discusions on… May 11, 2026 at 7:32 pm
  • Editorial Team
    Editorial Team added an answer You can use PathGetCharType function, PathCleanupSpec function or the following… May 11, 2026 at 7:32 pm

Related Questions

At the company I work for, I have created a Error Logging class to
I'm writing a WinForms app which has two modes: console or GUI. Three projects
Say I have a variable named choice it is equal to 2. How would
I need some help ... I'm a bit (read total) n00b when it comes

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.