Cancel PHP Unlock

I am having a problem with the unlink function.

I have a page that, when updating, looks for a directory for newly added files. The user can choose to manage files and also delete any file. However, when a user deletes a file, there is an almost 5 second delay before actually deleting the file from the server directory. In the meantime, if the user updates the browser, the same file that should have been deleted appears again as a new file. The problem is that if the user deletes this file again, the file no longer exists due to this initial delay ...

Any thoughts on this? It drives me crazy and doesn't know how to fix this situation ...

+4
source share
2 answers

One solution might be to create a new file when calling the unlink () function and the name of the new file is $ original_filename. "_ deleted". Then, when you list the files, exclude any ending with "_deleted". Then you just need to worry about clearing all the "_deleted" files so often with the cron job.

  function my_unlink($filename){ touch($filename.'_deleted'); unlink($filename); } function list_files(){ if ($handle = opendir('.')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && !preg_match('/_deleted$/',$entry)) { echo "$entry\n"; } } closedir($handle); } } 
0
source

clearstatchache(true, $file) is still worth a try, although I am pessimistic after unlink documentation.

There may be too many files in a directory, and using multiple directories can help (using directories with the first two characters of the file name).

However, my hope is that the listing overview page is cached. Using

 header("Cache-Control: no-cache, must-revalidate"); 

or so it can help.

0
source

Source: https://habr.com/ru/post/1480177/


All Articles