LOG4PHP-186: LoggerAppenderRollingFile: Don't clear the entire stat cache on an append if possible.
git-svn-id: https://svn.apache.org/repos/asf/logging/log4php/trunk@1394975 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3125af6..aa3ef3a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -21,6 +21,7 @@
</properties>
<body>
<release version="2.3.0" date="SVN">
+ <action date="2012-10-06" type="update" issue="LOG4PHP-186" dev="Ivan Habunek" due-to="Rasmus Lerdorf" due-to-email="rasmus at lerdorf dot com">Don't clear the entire stat cache on an append.</action>
<action date="2012-10-06" type="add" issue="LOG4PHP-141" dev="Ivan Habunek">Allow setting of a default renderer.</action>
<action date="2012-09-08" type="update" issue="LOG4PHP-120" dev="Ivan Habunek" due-to="Michal Vanek" due-to-email="michal dot vanek at gmail dot com">Fixed LoggerAppenderDailyFile to rollover on date change in long running scipts.</action>
<action date="2012-05-29" type="update" dev="Ivan Habunek">Removed $_ENV and $_SERVER access from LoggerMDC.</action>
diff --git a/src/main/php/appenders/LoggerAppenderRollingFile.php b/src/main/php/appenders/LoggerAppenderRollingFile.php
index 5b262d7..80b6462 100644
--- a/src/main/php/appenders/LoggerAppenderRollingFile.php
+++ b/src/main/php/appenders/LoggerAppenderRollingFile.php
@@ -80,6 +80,14 @@
protected $compress = false;
/**
+ * Set to true in the constructor if PHP >= 5.3.0. In that case clearstatcache
+ * supports conditional clearing of statistics.
+ * @var boolean
+ * @see http://php.net/manual/en/function.clearstatcache.php
+ */
+ private $clearConditional = false;
+
+ /**
* Get the maximum size that the output file is allowed to reach
* before being rolled over to backup files.
* @return integer
@@ -88,6 +96,13 @@
return $this->maxFileSize;
}
+ public function __construct($name = '') {
+ parent::__construct($name);
+ if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
+ $this->clearConditional = true;
+ }
+ }
+
/**
* Implements the usual roll over behaviour.
*
@@ -197,7 +212,12 @@
}
// Stats cache must be cleared, otherwise filesize() returns cached results
- clearstatcache();
+ // If supported (PHP 5.3+), clear only the state cache for the target file
+ if ($this->clearConditional) {
+ clearstatcache(true, $this->file);
+ } else {
+ clearstatcache();
+ }
// Rollover if needed
if (filesize($this->file) > $this->maxFileSize) {