Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Usuwanie plików z folderu
graft
post
Post #1





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 24.03.2007

Ostrzeżenie: (0%)
-----


Pomóżcie spece....

Znalazłem w sieci taki kod (cache):
  1. <?php
  2. // Settings
  3. $cachedir = 'cache/'; // Directory to cache files in (keep outside web root)
  4. $cachetime = 3600; // Seconds to cache files for
  5. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  6.  
  7. // Ignore List
  8. $ignore_list = array(
  9. 'domena.com/rss.php',
  10. 'domena.com/search/'
  11. );
  12.  
  13. // Script
  14. $page = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Requested page
  15. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  16.  
  17. $ignore_page = false;
  18. for ($i = 0; $i < count($ignore_list); $i++) {
  19. $ignore_page = (strpos($page, $ignore_list[$i]) !== false) ? true : $ignore_page;
  20. }
  21.  
  22. $cachefile_created = ((@file_exists($cachefile)) and ($ignore_page === false)) ? @filemtime($cachefile) : 0;
  23.  
  24. // Show file from cache if still valid
  25. if (time() - $cachetime < $cachefile_created) {
  26.  
  27. //ob_start('ob_gzhandler');
  28. @readfile($cachefile);
  29. //ob_end_flush();
  30. exit();
  31.  
  32. }
  33.  
  34. // If we're still here, we need to generate a cache file
  35.  
  36.  
  37. ?>

Działa dobrze i zapisuje do folderu /cache/ pliki, ale robi się bajzel, ponieważ strona ma dużo podstron i przez kilka dni mam wiele tysięcy plików zajmujących kilka GB.

Wymyśliłem sobie, żeby podczas tworzenia pliku 1234.cache usuwać pliki starsze niż $cachetime.
Jaką komendą usuwać? Unlink ale co? I czy w ogóle będzie to optymalne?

Z góry dzięki za podpowiedź...
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 14:34