Execute file in server after window is closed

Reply

Join Date: Sep 2005
Posts: 1,081
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Execute file in server after window is closed

 
0
  #11
May 1st, 2007
Originally Posted by mahe4us View Post
Hi w_3rabi,

Thankyou for your reply. Actually I made an application that users(doesnt have sessionid or registration in site) just come to site and add the products to their list. I maintained a temporary table which contains the products lists. If the users selected the products and send mail to me then the temporary table will clear. otherwise the user just selected the products and didnt send the mail to me and close the window then the table doesnt clear....... so only i want to erase contents in table once the user closed the window.

i think the detail may be just brief.... sorry.
thanks...
Why not just delete the temporary table when the users session is deleted?
(or when session expires).

Or you could just have a query that would check for temporary tables that have expired, and run the query every time a new table is created.

eg:

[PHP]$sql = "SELECT id from temp_table_name where update < 'NOW() - 3600'";[/PHP]

or if you have a db based session:

[PHP]

$sql = "SELECT t.id as tableid from temp_table_name as t LEFT JOIN session_table_name AS s ON (s.id = t.sessionid) where s.expires < NOW()";

[/PHP]

You don't really need to use cron. If you're worried about server/db load, just cache the last "cleanup" time to a file. Then If the last cleanup time was over 1 hour or so, runt he "cleanup" query again.

One problem I can see with using the window onunload event is that it doesn't tie into a users session. A user may have multiple windows open. Then may have not meant to close the window, and they still want their list of products there.

An expiration time linked to the session is better.

The window.onunload event with a new XMLHTTPRequest call does work though if you're sure the user only has one window open, and the one window represents a session. (common with Web2.0 designs).
Last edited by digital-ether; May 1st, 2007 at 8:29 am.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 54
Reputation: mahe4us is an unknown quantity at this point 
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Re: Execute file in server after window is closed

 
0
  #12
May 3rd, 2007
Hi digital-ether,

Thank you for your great reply. I really get some ideas from your reply. I have store the each sessionid obtained from session_id() in the temporary table. As you told I just check the sessionid available in the table and check whether it is active or not. once it not active then i delete it using your query.

Thank
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: castis is an unknown quantity at this point 
Solved Threads: 0
castis castis is offline Offline
Newbie Poster

Re: Execute file in server after window is closed

 
0
  #13
Oct 5th, 2009
Not sure if this is even still relevant but

  1. ignore_user_abort(1);

will continue to execute the script if the user closes the browser window.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 178
Reputation: codejoust is an unknown quantity at this point 
Solved Threads: 18
codejoust's Avatar
codejoust codejoust is offline Offline
Junior Poster

Re: Execute file in server after window is closed

 
0
  #14
Oct 5th, 2009
I simply would use an expiring session cookie.
That way, you wouldn't have to worry about the database usage and cron jobs.
Usually, it isn't a good idea to store temporary information on the server.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,023
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 131
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster
 
-1
  #15
Oct 5th, 2009
Originally Posted by codejoust View Post
I simply would use an expiring session cookie.
That way, you wouldn't have to worry about the database usage and cron jobs.
Usually, it isn't a good idea to store temporary information on the server.
Ditto.

BTW: why did this thread get resurrected after two and a half years?
Happy Humbugging Christmas
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC