Log-how many php files are suitable for reading and writing?

Source: Internet
Author: User
Use workman as a php framework for scheduled tasks. Logs are written to record whether the scheduled task is successful or failed. When the log file size is 70 MB, the scheduled task is interrupted and logs cannot be read from the background. Ask, php writes a log file or reads... a scheduled task framework for php in terms of using workman.
Logs are written to record whether the scheduled task is successful or failed. When the log file size is 70 MB, the scheduled task is interrupted and logs cannot be read from the background.
Could you tell me how many log files are suitable for php to write or read log files? I have read the article saying that 1 GB of log files can also be read, but how can a common website control the size of log files?

Reply content:

Use workman as a php framework for scheduled tasks.
Logs are written to record whether the scheduled task is successful or failed. When the log file size is 70 MB, the scheduled task is interrupted and logs cannot be read from the background.
Could you tell me how many log files are suitable for php to write or read log files? I have read the article saying that 1 GB of log files can also be read, but how can a common website control the size of log files?

When concurrency is high, it is locked when the same file is read and written at the same time.
When reading a file, as long as the file is not fopen, most of them do not matter, GB of files are OK.
You can use the fgets method to open a file pointer and then read the file one row at a time.

I don't know much about the backend, but do I feel that such data should be configured on the server? Or php. ini configuration?

It can be read and written no matter how large it is. It depends on how you read it. It is a read row, not the entire file is read into the memory.

Is it time-out? The default php running time is 30 seconds. In this case, you should set the timeout to no limit, as if it was a timeset_time_limit(0);I don't quite remember.

It's okay.
However, the execution is sometimes restricted (that is, set_time_limit)
However, if you change it to 0, a large number of processes may not end after a certain step (for example, the database cannot be connected), thus exhausting system resources.

Therefore, we recommend that you call shell_exec to run the php script that processes logs in cli mode.

php.ini max_execution_time memory_limitphp-fpm.conf request_terminate_timeout

It may be that the memory exceeds the configured maximum value or the execution time exceeds the limit.

File_get_contents and file read the entire file into the memory.
Therefore, when opening a large file, you should use fopen to obtain the file pointer (file stream), and then use fgets to read a row.
Http://cn2.php.net/fgets

I don't know how you use this framework to write log files. I use the error_log () function provided by PHP. The working method is to append new logs to the end of the file, the actual test is too large to several GB, probably because it is only written at the end of the file, not read.
In my understanding, since it is a log file that records success, it should be written and not read? You can try to write some code into the log of the analysis framework to see what the logic is.

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.