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

  • SEARCH
  • Home
  • 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 8677255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:24:42+00:00 2026-06-12T20:24:42+00:00

I have a web app that stores some objects in the user session so

  • 0

I have a web app that stores some objects in the user session so it doesn’t have to keep calling to the database every time there’s an AJAX hit to the server.

I want to write some cleanup/save functions that are triggered when the user closes the browser tab or navigates away from the page.

Is the session “destroyed” (i.e. calls __destruct for any objects it contains) if a user navigates away from the page – or is it better to handle this client side with a javascript that sends an AJAX request when the user navigates away?

  • 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. Editorial Team
    Editorial Team
    2026-06-12T20:24:43+00:00Added an answer on June 12, 2026 at 8:24 pm

    The session is in PHP is not defined as a class. Instead, we have a set of session functions to manipulate the session. To make sure that you have destroyed the session, you need to explicitly call :

       session_destroy();
    

    If you have not destroyed the session, the session will do garbage collection after the session timeout. The garbage collection depends on the following parameters – session.gc_maxlifetime, session.gc_divisor and session.gc_probability. To make sure that the garbage collection runs on every session, you will have to add session.gc_probability to 100%. But it definitely add an overhead to the server, especially if yours is a high traffic server.

    If you do not explicitly keep track of the sessions and destroy it after use, you are leaving some part of the session management to the OS. See the note from PHP.net:

    Note: If you are using the default file-based session handler, your
    filesystem must keep track of access times (atime). Windows FAT does
    not so you will have to come up with another way to handle garbage
    collecting your session if you are stuck with a FAT filesystem or any
    other filesystem where atime tracking is not available. Since PHP
    4.2.3 it has used mtime (modified date) instead of atime. So, you won’t have problems with filesystems where atime tracking is not
    available.

    The best way is to send a flag via Ajax call when the browser or tab is closed. You can detect it via : window.onunload event of javascript.

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

Sidebar

Related Questions

We are developing the Web App that will have user subscription to a specific
We have a web app that stores and works with data with character encoding
I have some code that downloads a plist from a web server and stores
I have a MVC2 web app without a database that is being hosted by
I have a web app that runs fine in Visual web developer. But when
I have a web app that reads data from a SQL DB that contains
I have a web app that has a big and complex form (fields, checks,
We have an web app that is talking to Netsuite via Netsuite's web services.
I have a web app that I've recently applied a jQuery ThemeRoller theme to.
I have a web app that lets a client define a daily rate for

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.