check if the file is in use with php

Asked

Viewed 334 times

2

Guys I have a file called photo.zip, where people can download it on my site. I want to create a php file that crontab will run every 10 minutes, and check if the file is being downloaded by someone. If it’s not he erases the file.

Someone knows how to do it.

  • Just a suggestion @Hugo: put in the question title check with php to see if there is a download in progress. Usually the term file in use is used to designate an open file by an operating system application that may not be a download.

1 answer

2


First, we must know which is your server.

If you are Apache, you must access this documentation section (access logs) and check which access file.

If it’s IIS, go to this section of documentation and see where the log files are. From what you posted I believe that is not this.

In both cases, you have to check if your server version is in accordance with the documentation I suggested.

The second step is to make these logs accessible to for the query via php. For security reasons, I recommend that your crontab php script, take a copy of this file to another directory and check.

Another alternative, and I find this more recommended. Is you create on the access page a button that will make an action to manage the file download. I believe there must be php/Avascript/Ajax processing so that while the download is in progress, it generates some flag (e.g. a .lock-[date]-[time] file) that is deleted after the download is finished or stopped. When your crontab program runs and does not find any flags, then it deletes the file.

  • As for this second alternative, I posted a question to know if it is possible, only by php/javascript, without consulting the apache logs, to accumulate this information. There are several download sites that do this, I believe there should be client-side tools already.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.