Destroying Objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • STEPHEN GOODE

    Destroying Objects

    I have a need to notice when a user leaves a site so I can implement
    destructors for objects. I know that PHP doesn't supply an object
    destructor. I can code that myself. What I don't know how to do is know when
    a session is no longer needed, for example, when a user leaves the site or
    closes the browser. I thought that register_shutdo wn_function() would help,
    but it shuts down at the end of the session regardless of whether I plan to
    start it again on the next page.

    I'd appreciate any ideas.


  • Kevin

    #2
    Re: Destroying Objects

    There is no way to reliably detect if a user has left the site/closed their
    browser/computer struck by lightning. You could have pages automatically
    refresh periodically (or use a javascript call) and check for sessions older
    than that period, but it wouldn't be infallible.

    What is the end result you are trying to accomplish?

    - Kevin

    "STEPHEN GOODE" <rexgoode@veriz on.net> wrote in message
    news:ZmuKd.448$ RI.127@trnddc06 ...[color=blue]
    >I have a need to notice when a user leaves a site so I can implement
    >destructors for objects. I know that PHP doesn't supply an object
    >destructor. I can code that myself. What I don't know how to do is know
    >when a session is no longer needed, for example, when a user leaves the
    >site or closes the browser. I thought that register_shutdo wn_function()
    >would help, but it shuts down at the end of the session regardless of
    >whether I plan to start it again on the next page.
    >
    > I'd appreciate any ideas.
    >
    >[/color]


    Comment

    • Joshua Beall

      #3
      Re: Destroying Objects

      "STEPHEN GOODE" <rexgoode@veriz on.net> wrote in message
      news:ZmuKd.448$ RI.127@trnddc06 ...[color=blue]
      >I have a need to notice when a user leaves a site so I can implement
      >destructors for objects. I know that PHP doesn't supply an object
      >destructor. I can code that myself. What I don't know how to do is know
      >when a session is no longer needed, for example, when a user leaves the
      >site or closes the browser. I thought that register_shutdo wn_function()
      >would help, but it shuts down at the end of the session regardless of
      >whether I plan to start it again on the next page.
      >
      > I'd appreciate any ideas.[/color]

      As Kevin pointed out there is no foolproof way to know when a user has left
      the sight.

      A typical method (used by PHP's builtin session handler, too) is to assume
      that a certain period of inactivity means they left the site.

      If you built a custom session handler, on cleanup of dead sessions you could
      have it execute your "visitor left the site" code for all sessions that
      expired. The disadvantage, of course, is that it will not be run for
      however long you set the session expiry to be. For instance, is sessions
      expire after 15 minutes of inactivity, then the "visitor left site" code
      will not get run until they've already been gone 15 minutes.

      Kevin also suggested some JS solutions. You could try those. As usual, the
      caveat is that JS can easily be disabled, might be broken in the visitor's
      browser, etc.

      HTH,
      -Josh


      Comment

      Working...