SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Execute Code When Session Expires

    Hey,

    I want to update the logs table every time a session ends, rather than doing it for every page I am going to save the log from each individual page to a flat file then update the database when the session is over.

    The problem is...is there a way to execute this query when the session ENDS? Not necessarily me killing the session, but the browser being closed, time expiring, etc..

    Is this possible?


  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    What event typifies the session end for you then?

  3. #3
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whenever it isn't killed by me, but it expires. Such as when the user closes their browser.


  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Search turned up a couple of posts that might help you, had you already seen these?

    http://www.sitepoint.com/forums/show...t=session+kill

    http://www.sitepoint.com/forums/show...t=session+kill

  5. #5
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, let's turn back a bit.

    In terms of logging user's actions, do you think the best way would be just to write to a flat file, then push it to the database with a CRON job?


  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    How do you expect to log a user action such as closing a browser window? or lost connection to the internet?

    Sessions seems to be the accepted normal way of maintaining state, though you could use a cookie.

  7. #7
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chatmasta View Post
    Whenever it isn't killed by me, but it expires. Such as when the user closes their browser.
    There is no way you can determine that a user has closed a browser using PHP, you can only determine that the user hasnt issued a page request for X amount of time, this will need to be done by running a management script, CRON is the best way to do this.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  8. #8
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cups, that is not what I'm logging. I'm logging page requests, etc...and putting them in a userXXX.log file as each page is loaded. Then at one point, I want to push that flat file to the MySQL database. What I am struggling with is finding when to do that.


  9. #9
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Why do you not want to log the page change as it happens ?
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  10. #10
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because I don't want every single page load to have a MySQL query.


  11. #11
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chatmasta View Post
    Because I don't want every single page load to have a MySQL query.
    So your existing pages dont access your database now ??

    Your going to need to do some file control if you want to save the log of your users to a file on the server, you could have several connections tryig to access the same file at the same time.

    Good luck

    edit: OK just reread that your doing one file for each user, sorry
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  12. #12
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    So your existing pages dont access your database now ??
    It's just a matter of having the least MySQL overhead possible on each page.

    I guess a better question is - what do you find the most efficient method for logging?



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •