High performance php log solution idea

WBOY
Release: 2016-07-28 08:26:48
Original
1238 people have browsed it

Imagination of high-performance php logging solution

High-performance php logging solution

The log is completed in two steps:

  • Log information is written in real time in the memory cache to minimize performance overhead
  • crontab timing from Collect and write to database or file in memory cache

Specific algorithm: (laravel framework)

  • Set a constant: imax=10000000, two variables iwrite=1, iread=1. (iwrite Log writing pointer, iread log reading pointer, iread <=iwrite, the two variable values ​​​​are stored in the memory cache)
  • Every time a log is generated, use "Cache::increment (iwrite)" to obtain iwrite Incremental value, if the value is greater than imax, reset to 1, store the log in the cache, key: 'log_'+iwrite, value: log content
  • crontab calls the command line every 30 seconds to collect logs, use "Cache ::increment(iread)" gets the incremental value of iread. If it is equal to iwrite, stop. If the value is greater than imax, reset to 1, read the log from the cache and store it in batches. Finally delete the log from cache.

Memory cache can use apc, xcache, etc.

Cache::increment , belongs to laravel framework Built-in methods, if it is not the laravel framework, you can encapsulate it yourself.

I don’t have time yet, so I’ll record my thoughts first, When you have time in the future, practice it and then send out the code.

The above has introduced the idea of ​​a high-performance PHP logging solution, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!