mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
34 lines
865 B
PHP
34 lines
865 B
PHP
<?php
|
|
|
|
class logs
|
|
{
|
|
static $_last_check = array();
|
|
|
|
static function rotate($filepath)
|
|
{
|
|
$limit = (1024 * 1024 * 20);
|
|
|
|
$date_obj = new DateTime('-3 min');
|
|
$check_time = $date_obj->format('U');
|
|
|
|
if ( ! isset(self::$_last_check[$filepath]) || self::$_last_check[$filepath] < $check_time) {
|
|
clearstatcache();
|
|
|
|
if (file_exists($filepath) && filesize($filepath) > $limit) {
|
|
$n = 1;
|
|
while (file_exists($filepath . '.' . $n))
|
|
$n ++;
|
|
if (copy($filepath, $filepath . '.' . $n)) {
|
|
$handle = fopen($filepath, 'r+');
|
|
ftruncate($handle, 0);
|
|
fclose($handle);
|
|
}
|
|
}
|
|
|
|
self::$_last_check[$filepath] = $check_time;
|
|
}
|
|
|
|
return;
|
|
}
|
|
}
|