PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Caching » Cache_Lite » Bug #7598

PHP Warnings on cache directory creation

Details

Submitted2006-05-10 18:23 UTC
Fromfrederes at free dot fr
Assignedfab
StatusClosed
PackageCache_Lite
PHP Version4.4.2
OSLINUX / WINDOWS XP
Roadmaps(Not assigned)

Comments

[2006-05-10 18:23 UTC] frederes at free dot fr

Description:
------------
Bonjour,

Je me permet de vous écrire pour vous signaler un "petit bug" sur la très bonne classe PEAR::Cache_Lite que vous avez développée :
J'ai des Warning PHP qui apparaissent dans cette classe a priori, cela viendrait je pense d'un simple test à faire au préalable à la création du répertoire de cache (mkdir)

Warning: /usr/local/lib/php/Cache/Lite.php [753] : fopen(/tmp/cache_1/cache_17/cache_170/cache_c21f969b5f03d33d43e04f8f136e7682_b07ee23062977c62646679a117a4c152): failed to open stream: No such file or directory
Warning: /usr/local/lib/php/Cache/Lite.php [770] : mkdir(/tmp/cache_1/): File exists

Fichier Lite.php / ligne 765 / fonction _write() :

...
if (($try==1) and ($this->_hashedDirectoryLevel>0)) {
$hash = md5($this->_fileName);
$root = $this->_cacheDir;
for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {
$root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';

// faire un test ici : si le dossier n'existe pas déjà alors....
@mkdir($root, $this->_hashedDirectoryUmask);
}
$try = 2;
} else {
$try = 999;
...

Pour info, ceci semble être apparu depuis que j'utilise la classe PEAR:Log pour la gestion d'erreur, voici ma fonction handler des erreurs :

<?php
require_once "Log.php";

$conf = array('error_prepend' => '<font color="#ff0000"><tt>',
'error_append' => '</tt></font>');

$logger=&Log::singleton('display', '', '', $conf, PEAR_LOG_DEBUG);

function errorHandler($code, $message, $file, $line)
{
global $logger;

/* Map the PHP error to a Log priority. */
switch ($code)
{
case E_WARNING:
case E_USER_WARNING:
$priority = PEAR_LOG_WARNING;
break;
case E_NOTICE:
case E_USER_NOTICE:
$priority = PEAR_LOG_NOTICE;
break;
case E_ERROR:
case E_USER_ERROR:
$priority = PEAR_LOG_ERR;
break;
default:
$priotity = PEAR_LOG_INFO;
}

$logger->log($file." [".$line."] : ".$message, $priority);
}

set_error_handler("errorHandler");
?>

Et ma config de Cache_Lite :

<?php
require_once "Cache/Lite.php";
require_once "Cache/Lite/Output.php";

if ($ON_SERVEUR)
{
if (!isset($DEBUG["b_nocache"]))
$b_cache=true;
else
$b_cache=$DEBUG["b_nocache"]==1?false:true;
}
else
$b_cache=false;

$options=array(
"cacheDir" => "/tmp/monsite/",
"caching" => $b_cache,
"lifeTime" => 3600, /* secondes */
"fileLocking" => true,
"writeControl" => true,
"readControl" => false,
"readControlType" => "crc32",
"pearErrorMode" => CACHE_LITE_ERROR_DIE,
"fileNameProtection" => true,
"automaticSerialization" => true,
"memoryCaching" => false,
"onlyMemoryCaching" => false,
"memoryCachingLimit" => 1000,
"automaticCleaningFactor" => 50,
"hashedDirectoryLevel" => 3
);

$cache=new Cache_Lite($options);
$cache_page=new Cache_Lite_Output($options);
?>

Enfin, une bonne chose serait peut-être de créer le répertoire de stockage de base des fichier s'il n'existe pas.
Par exemple, je l'ai défini à /tmp/monsite/ et s'il n'existe plus (si je vide mon répertoire /tmp/ par exemple...) ça renvoie un warning je crois.

Expected result:
----------------
no PHP warnings

Actual result:
--------------
Warning: /usr/local/lib/php/Cache/Lite.php [753] : fopen(/tmp/cache_1/cache_1f/cache_1ff/cache_c21f969b5f03d33d43e04f8f136e7682_039e0eb4ba067f2c51834c4906b9f7b1): failed to open stream: No such file or directory

Warning: /usr/local/lib/php/Cache/Lite.php [770] : mkdir(/tmp/cache_1/): File exists

[2006-05-28 12:55 UTC] fab at php dot net

This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.