[ 
https://issues.apache.org/jira/browse/LOG4PHP-138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13023243#comment-13023243
 ] 

Bhumir Sheth commented on LOG4PHP-138:
--------------------------------------

Hi Christian,

Thank you for your help.

We had tried the flock() function within rollOver function and modified as 
below:


private function rollOver() {

   if (flock($this->fp, LOCK_EX)) {

     // If maxBackups <= 0, then there is no file renaming to be done.
    if($this->maxBackupIndex > 0) {
      $fileName = $this->getExpandedFileName();

      // Delete the oldest file, to keep Windows happy.
      $file = $fileName . '.' . $this->maxBackupIndex;
      if(is_writable($file))
        unlink($file);
      // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
      for($i = $this->maxBackupIndex - 1; $i >= 1; $i--) {
        $file = $fileName . "." . $i;
        if(is_readable($file)) {
          $target = $fileName . '.' . ($i + 1);
          rename($file, $target);
         }
       }

//   $this->close();

   // Rename fileName to fileName.1
//   $target = $fileName . ".1";
//   $file = $fileName;
//   rename($file, $target);

       copy($fileName, $fileName . ".1");
     }

     ftruncate($this->fp, 0);
     fseek($this->fp, 0);

     flock($this->fp, LOCK_UN);
     fclose($this->fp);

     //unset($this->fp);
     $this->activateOptions();
     $this->setFile($fileName, false);
   }
 }

By implementing flock() within rollOver() function we were able to avoid the 
error message and issue of sequence of back up files. However, the above 
implementation creates another issue. Sometimes it creates back up of log files 
having small size (i.e. 2KB or 6KB) which is smaller than maximum file size 
defined (1 MB).

We are using this application on Windows operating system.

We would appreciate your further help on this.

Best regards,

Bhumir Sheth

> Permission denied while renaming log file when hundred of users are accessing 
> the application
> ---------------------------------------------------------------------------------------------
>
>                 Key: LOG4PHP-138
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-138
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>    Affects Versions: 2.0
>         Environment: Windows operating system
>            Reporter: Bhumir Sheth
>            Priority: Critical
>             Fix For: 2.0
>
>
> Hi,
> We have developed a web application and integrated with log4php, which is 
> used by hundred of users. When the size of log file exceed the maximum file 
> size, it calls rollOver() function to create back up file for log file and 
> truncate the current log file. 
> We faced one error while renaming the file from "filename" to "filename.1". 
> This error is generated when hundred of users are accessing the application 
> at the same time. The error is generated as below:
> PHP Warning:  
> rename(C:\PHP\errors/Test_Module.log,C:\PHP\errors/Test_Module.log.1) [<a 
> href='function.rename'>function.rename</a>]: Permission denied in 
> C:\Inetpub\wwwroot\Test_Application\System\System_Logger\log4php\src\main\php\appenders\LoggerAppenderRollingFile.php
>  on line 140
> Also, back up of log files are not created in sequence when above warning is 
> generated. For example, log file "Test_Module.log" is already exists and 
> rollOver() function is called to create new back up file then it creates 
> "Test_Module.log.4" instead of "Test_Module.log.1".
> Moreover, log file has given all the required permissions and it works fine 
> while appending the logs.
> We would appreciate if you can help us by providing a solution or work-around 
> for resolving this issue.
> Please let me know if more details are required.
> Thank you.
> Best regards,
> Bhumir Sheth

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to