Log-php read and write files how much more appropriate?

Source: Internet
Author: User
Keywords Log Php file
Tags php write
In the use of workman a PHP aspect of the scheduled task framework.
By timing the log to record the success or failure of the scheduled task, the log file size of 70M when the level of the scheduled task is broken, the background read logs can not read.
Ask, PHP write log file or read log file, general log file is how much more appropriate? Look up there are articles saying that 1G log files can also be read, but how to control the size of the normal Web site log file?

Reply content:

In the use of workman a PHP aspect of the scheduled task framework.
By timing the log to record the success or failure of the scheduled task, the log file size of 70M when the level of the scheduled task is broken, the background read logs can not read.
Ask, PHP write log file or read log file, general log file is how much more appropriate? Look up there are articles saying that 1G log files can also be read, but how to control the size of the normal Web site log file?

It is possible that the concurrency is high, while reading and writing the same file is locked.
For reading files, as long as you do not fopen a file, most of it does not matter, 100G files are no problem
It is not problematic to use the Fgets method to open a pointer to a file and then loop through the file one line at a line.

Do not understand the backend, but feel that such data should not be configured on the server? or php.ini configuration?

No matter how much you can read and write. It depends on how you read it. is read one line at a time, not the entire file is read into memory.

Is it time-out? The default PHP run time is 30 seconds, you should set the time-out to unlimited, as if it is set_time_limit(0); , do not remember.

Most of them are no problem.
But enforcement is often limited (which is what people call Set_time_limit).
But to change it to 0, once a step is out of the question (such as a database cannot connect), it can cause a large number of processes to end, thus exhausting system resources.

So it is recommended that you call Shell_exec, the PHP script that executes the log with CLI mode

php.ini max_execution_time memory_limitphp-fpm.conf request_terminate_timeout

It is possible that the memory exceeds the configured maximum, or the execution time exceeds the limit.

File_get_contents and file are read into the memory.
So when you open a large file, you should use fopen, get the file pointer (the file stream), and then read it fgets a line.
Http://cn2.php.net/fgets

I do not know how you use this framework to write to the log file, I use PHP comes with the error_log () function, the way is always append new log to the end of the file, actually tried to a few G no problem, probably because it is only to the end of the file to write, not read.
As I understand it, since it is a log file of success, it should only be written, not read it? You can try parsing the framework's log to write part of the code to see what the logic is.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.