On 4 Mar 2012, at 15:31, Nibin V M wrote:

> in fact....I really need to remove the file ( which will be created for
> every access - making a copy from another location ). I can't leave that
> file alone for ever in the user disk space! :(

Ash is right in that this is exactly what sessions are used for, so unless the 
data you are storing for the user is fairly large you'd be better off using 
them: http://php.net/session

Why do you need to copy the file? Might be an idea to describe what you're 
actually doing rather than focus on this particular part. Do you make changes 
to the file after you've copied it? If not, why not use the original copy? If 
you do modify is, how and why? I'll bet there's a better way to do what you're 
doing.

If you absolutely need to make these copies, your best bet is to have a script 
executed by cron periodically to clean up files with a last modified timestamp 
older than n seconds, and make sure each page request calls the touch function 
for that user's file to updated the file's timestamp.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

> On Sun, Mar 4, 2012 at 9:01 PM, Ashley Sheridan 
> <a...@ashleysheridan.co.uk>wrote:
> 
>> **
>> On Sun, 2012-03-04 at 20:49 +0530, Nibin V M wrote:
>> 
>> Hello,
>> 
>> I need to run a few commands when a user close the browser tab. That is, I
>> have a php page ( index.php ) and it will create a temporary file to track
>> some stuffs. That temporary file should be removed, when the user close the
>> browser tab. Is there any way to achieve this?
>> 
>> Thank you,
>> 
>> 
>> 
>> Not reliably. There are events in Javascript that you can use to trigger
>> an Ajax call (such as onbeforeunload and onunload) but these work slightly
>> differently from browser to browser and may not allow you to execute
>> anything on the browser if the user is navigating away from the site or
>> closing the tab/window.
>> 
>> Why can't you use the session for this, and allow the session to expire
>> after a certain period of inactivity, which would be better than
>> reinventing what sounds like session behaviour.
>> 
>>  --
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>> 
>> 
>> 
> 
> 
> -- 
> Regards....
> 
> Nibin.
> 
> http://TechsWare.in


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to