RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3027 | Replies: 11
Reply
Join Date: Sep 2006
Posts: 53
Reputation: mahe4us is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Execute file in server after window is closed

  #1  
Apr 30th, 2007
Hi all,

Iam trying to tigger some file which will be working in backend once the window is closed in php. Iam using onunload function in javascript but it triggers the file once we leave that particular page only. If we closed the window it didnt do anything. Anybody have idea how to execute file in server once the window was closed. Is there any possibilites?

Thanks in advance...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 158
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: Execute file in server after window is closed

  #2  
Apr 30th, 2007
may i ask why you want to do it that way??
i never did something like this , but i guess if you want to execute something on the server other than web page you could put the php code in a file and execute it without browser
Reply With Quote  
Join Date: Sep 2006
Posts: 53
Reputation: mahe4us is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Re: Execute file in server after window is closed

  #3  
Apr 30th, 2007
Originally Posted by w_3rabi View Post
may i ask why you want to do it that way??
i never did something like this , but i guess if you want to execute something on the server other than web page you could put the php code in a file and execute it without browser


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...
Reply With Quote  
Join Date: Oct 2006
Location: London
Posts: 42
Reputation: UrbanSky is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
UrbanSky UrbanSky is offline Offline
Light Poster

Re: Execute file in server after window is closed

  #4  
Apr 30th, 2007
Basically you need to remember that php is a scripting language that is designed to be excecuted before a page is sent to a browser and scripts will only be processed when page is called and will only continue while a page is loading.

So if a window is closed the connection is broken, the script execution will stop.

Having said that I can think of an option but it is not very pretty.

Not knowing what your script is doing and why it needs to be executed on the unload function, it makes it slightly more difficult to be helpful.

I am going to assume that you are using AJAX in the unload function otherwise I can't see how else you are making a call to the server (except maybe opening a new window).

What I would propose is that instead of running the script directly your could use the function call to write the information that you are sending to the server, into a storage file or database, ready for processing.

The setup a cronjob that executes every x minutes that processes the commands. This way it does not matter if the window is closed.

But this brings us back to the problem of the unload function, which will not be triggered if the window is closed. If you provide some more information then, we might be able to help a bit more.



Urban
Reply With Quote  
Join Date: Oct 2006
Location: London
Posts: 42
Reputation: UrbanSky is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
UrbanSky UrbanSky is offline Offline
Light Poster

Re: Execute file in server after window is closed

  #5  
Apr 30th, 2007
Sorry, was typing when the two replys came in above.
Reply With Quote  
Join Date: Oct 2006
Location: London
Posts: 42
Reputation: UrbanSky is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
UrbanSky UrbanSky is offline Offline
Light Poster

Re: Execute file in server after window is closed

  #6  
Apr 30th, 2007
Ok having read what you are trying to do, I would just place the information in a cookie and then if they visit my site again the first thing that I do is delete the cookie to clear the information.
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 158
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: Execute file in server after window is closed

  #7  
Apr 30th, 2007
Originally Posted by UrbanSky View Post
Ok having read what you are trying to do, I would just place the information in a cookie and then if they visit my site again the first thing that I do is delete the cookie to clear the information.

i just was thinking in the same thing .......
and i guess this is better and more professional way in saving the data at the client machine but still the problem is he want to delete the data after an email is sent .....
Reply With Quote  
Join Date: Sep 2006
Posts: 53
Reputation: mahe4us is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Re: Execute file in server after window is closed

  #8  
Apr 30th, 2007
Originally Posted by UrbanSky View Post
Ok having read what you are trying to do, I would just place the information in a cookie and then if they visit my site again the first thing that I do is delete the cookie to clear the information.


Hi UrbanSky,

Thankyou for your nice reply. I also have the idea to run a cron job to delete the contents in temporary table. But I would like to delete the contents without using cron job in the table. How could you call a function call for this purpose? may i know that...

thanku
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 158
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: Execute file in server after window is closed

  #9  
Apr 30th, 2007
you could put a link on the page to redirect him to another page which deletes from table then redirect to th email client



i guess ..............!!!!
Reply With Quote  
Join Date: Oct 2006
Location: London
Posts: 42
Reputation: UrbanSky is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
UrbanSky UrbanSky is offline Offline
Light Poster

Re: Execute file in server after window is closed

  #10  
Apr 30th, 2007
Bassically, I am not sure that you can. Becuase the script has to be run when the page is called by the browser. I think that you are over complicating the process, increasing bandwidth, increasing server load, etc.

Please explain why it is important to store the information in a centeral database table on the server. How is the email being send?(Is it by a send mail script or does the client have to use there email client to send you an email?)

Urban
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:03 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC