PHP Rotation



  • How do you make the logic of the php?

    Suppose the file runs every minute of the crown. A new file is created every time. How do we propose to rotate a day long?



  • The problem is, in determining when a new file should be created, or in adding the tape to the end of the file, rather than creating/rewriting each time a new one? Or is it possible that the file is supposed to be one in principle, but all the tapes are supposed to go in there and not be washed?

    Algorithm:

    (1) Determine what day it is now.
    (2) Ask the file name.
    (3) Make a record of it. If such a file does not exist, a new one will automatically be created

    If necessary 1 file log = 1 day:

    // Формируем сообщение и имя файла
    $message = "Тест сообщения\r\n";
    $file_name = date("Y_m_d")."_log.log"
    

    // Запись в файл
    $file = fopen("logs/$file_name", 'a+');
    fwrite($file, $message);

    If you need to be One fileand not created for every day a new one, to assign variables such values:

    // Формируем сообщение и имя файла
    $message = date("Y_m_d")."##Текст сообщения\r\n";
    $file_name = "log_file.log";

    // Запись в файл
    ...

    PHP record:

    // Формируем сообщение и имя файла
    ...
    // Запись в файл
    error_log($message, 3,"logs/".$file_name);

    Protocol Syslog

    PHP also has the function of sending messages to a system journal.

    • http://php.net/manual/ru/function.openlog.php - creates a system log connection for the programme
    • http://php.net/manual/ru/function.syslog.php - generates and sends a message to the system log.
    • http://php.net/manual/ru/function.closelog.php - closes the connection to the system log.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2