clearstatcache () de PHP cuestión

  • PolishHurricane
  • Mastermind
  • Mastermind
  • Avatar de Usuario
  • Registrado: Feb 17, 2005
  • Mensajes: 1585
  • Status: Offline

Nota Julio 23rd, 2010, 12:50 pm

Tengo un archivo que modificar varias veces en una secuencia de comandos y no se puede tener en caché porque corro filemtime () sobre ella. Así que tengo que usar clearstatcache después de que lo llame, Im preguntándose si...

En los parámetros de la función, se menciona que puede borrar el caché "realpath", nadie sabe qué es eso? O ¿alguien sabe el tamaño del caché de estadística real es? Leí en una página de error de PHP que es sólo una entrada grande? Ahora Im confundido...:(

Nota: Hice establecer los parámetros en TRUE y <file_path> y, de hecho todavía limpia el cache de ese archivo, es que no sé si todavía limpia el caché de todos los demás archivos.
There's no place like 127.0.0.1, badass part is now it's ::1
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Julio 23rd, 2010, 12:50 pm

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Registrado: Feb 10, 2004
  • Mensajes: 13455
  • Loc: Florida
  • Status: Offline

Nota Julio 24th, 2010, 1:40 am

Heres la fuente de clearstatcache en php PHP 5.2.14-si le ayuda.

C Código: [ Select ]
PHPAPI void php_clear_stat_cache(TSRMLS_D)
{
   if (BG(CurrentStatFile)) {
      efree(BG(CurrentStatFile));
      BG(CurrentStatFile) = NULL;
   }
   if (BG(CurrentLStatFile)) {
      efree(BG(CurrentLStatFile));
      BG(CurrentLStatFile) = NULL;
   }
   realpath_cache_clean(TSRMLS_C);
}
 
PHP_FUNCTION(clearstatcache)
{
   if (ZEND_NUM_ARGS()) {
      WRONG_PARAM_COUNT;
   }
   php_clear_stat_cache(TSRMLS_C);
}
  1. PHPAPI void php_clear_stat_cache(TSRMLS_D)
  2. {
  3.    if (BG(CurrentStatFile)) {
  4.       efree(BG(CurrentStatFile));
  5.       BG(CurrentStatFile) = NULL;
  6.    }
  7.    if (BG(CurrentLStatFile)) {
  8.       efree(BG(CurrentLStatFile));
  9.       BG(CurrentLStatFile) = NULL;
  10.    }
  11.    realpath_cache_clean(TSRMLS_C);
  12. }
  13.  
  14. PHP_FUNCTION(clearstatcache)
  15. {
  16.    if (ZEND_NUM_ARGS()) {
  17.       WRONG_PARAM_COUNT;
  18.    }
  19.    php_clear_stat_cache(TSRMLS_C);
  20. }


Al parecer, para realizar un seguimiento de sólo el último archivo utilizado. Hice la siguiente prueba. Si ejecuta la prueba tal y como son, y van en a través de FTP para eliminar los tres archivos txt, mientras que el guión es el sueño ()-ción, recibo errores durante los primeros dos archivos, y un mtime válido para el último archivo. Si me quite mi clearstatcache () llame, me da tres errores.

Esto me lleva a creer PHP sólo lleva un registro del último archivo, y no una colección de archivos que se usan en todo el guión.

PHP Código: [ Select ]
<pre><?php
 
$filenames = array(
   'one.txt',
   'two.txt',
   'three.txt'
);
 
foreach($filenames as $filename)
{
   file_put_contents($filename, $filename);
}
 
sleep(2);
 
foreach($filenames as $filename)
{
   printf('%1$s: %2$s%3$s', $filename, filemtime($filename), PHP_EOL);
}
flush(); ob_flush();
//clearstatcache();
 
sleep(10); // Delete files via FTP/SSH here
 
foreach($filenames as $filename)
{
   printf('%1$s: %2$s%3$s', $filename, filemtime($filename), PHP_EOL);
}
flush();
 
?></pre>
  1. <pre><?php
  2.  
  3. $filenames = array(
  4.    'one.txt',
  5.    'two.txt',
  6.    'three.txt'
  7. );
  8.  
  9. foreach($filenames as $filename)
  10. {
  11.    file_put_contents($filename, $filename);
  12. }
  13.  
  14. sleep(2);
  15.  
  16. foreach($filenames as $filename)
  17. {
  18.    printf('%1$s: %2$s%3$s', $filename, filemtime($filename), PHP_EOL);
  19. }
  20. flush(); ob_flush();
  21. //clearstatcache();
  22.  
  23. sleep(10); // Delete files via FTP/SSH here
  24.  
  25. foreach($filenames as $filename)
  26. {
  27.    printf('%1$s: %2$s%3$s', $filename, filemtime($filename), PHP_EOL);
  28. }
  29. flush();
  30.  
  31. ?></pre>


En el clearstatcache página del manual, la nota sobre la lista de argumentos Nombre de archivo del PHP 5.3 tan Im adivinar PHP 5.3 + realmente mantiene la memoria caché en la colección de archivos utilizado.

He intentado pasar los parámetros a clearstatcache en PHP 5.2.6 que he sentado aquí a mi lado. Me sale el siguiente error, que cuando miro hacia atrás en el código fuente de clearstatcache, tiene sentido debido a que su lanzamiento de un WRONG_PARAM_COUNT "," error theres cualquier momento uno o más argumentos pasados en 5.2 .*

Quote:
contar parámetro incorrecto para clearstatcache ()


Luego tenemos el código fuente para clearstatcache en PHP 5.3.3 que acepta argumentos. Al parecer, para utilizar sólo el argumento de nombre de archivo $ si el argumento es VERDADERO realpath sin embargo.

C Código: [ Select ]
PHPAPI void php_clear_stat_cache(zend_bool clear_realpath_cache, const char *filename, int filename_len TSRMLS_DC)
{
   /* always clear CurrentStatFile and CurrentLStatFile even if filename is not NULL
    * as it may contains outdated data (e.g. "nlink" for a directory when deleting a file
    * in this directory, as shown by lstat_stat_variation9.phpt) */
   if (BG(CurrentStatFile)) {
      efree(BG(CurrentStatFile));
      BG(CurrentStatFile) = NULL;
   }
   if (BG(CurrentLStatFile)) {
      efree(BG(CurrentLStatFile));
      BG(CurrentLStatFile) = NULL;
   }
   if (clear_realpath_cache) {
      if (filename != NULL) {
         realpath_cache_del(filename, filename_len TSRMLS_CC);
      } else {
         realpath_cache_clean(TSRMLS_C);
      }
   }
}
 
PHP_FUNCTION(clearstatcache)
{
   zend_bool  clear_realpath_cache = 0;
   char      *filename             = NULL;
   int        filename_len         = 0;
 
   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs", &clear_realpath_cache, &filename, &filename_len) == FAILURE) {
      return;
   }
 
   php_clear_stat_cache(clear_realpath_cache, filename, filename_len TSRMLS_CC);
}
  1. PHPAPI void php_clear_stat_cache(zend_bool clear_realpath_cache, const char *filename, int filename_len TSRMLS_DC)
  2. {
  3.    /* always clear CurrentStatFile and CurrentLStatFile even if filename is not NULL
  4.     * as it may contains outdated data (e.g. "nlink" for a directory when deleting a file
  5.     * in this directory, as shown by lstat_stat_variation9.phpt) */
  6.    if (BG(CurrentStatFile)) {
  7.       efree(BG(CurrentStatFile));
  8.       BG(CurrentStatFile) = NULL;
  9.    }
  10.    if (BG(CurrentLStatFile)) {
  11.       efree(BG(CurrentLStatFile));
  12.       BG(CurrentLStatFile) = NULL;
  13.    }
  14.    if (clear_realpath_cache) {
  15.       if (filename != NULL) {
  16.          realpath_cache_del(filename, filename_len TSRMLS_CC);
  17.       } else {
  18.          realpath_cache_clean(TSRMLS_C);
  19.       }
  20.    }
  21. }
  22.  
  23. PHP_FUNCTION(clearstatcache)
  24. {
  25.    zend_bool  clear_realpath_cache = 0;
  26.    char      *filename             = NULL;
  27.    int        filename_len         = 0;
  28.  
  29.    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs", &clear_realpath_cache, &filename, &filename_len) == FAILURE) {
  30.       return;
  31.    }
  32.  
  33.    php_clear_stat_cache(clear_realpath_cache, filename, filename_len TSRMLS_CC);
  34. }


No creo que tengo una copia del 5,3 por pasar mis pruebas en este momento.
Strong with this one, the sudo is.

Publicar Información

  • Total de mensajes en este tema: 2 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 207 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC