Scenario of high Performance PHP log

Source: Internet
Author: User
Scenario of high Performance PHP log

High Performance PHP log scheme

The log is completed in two steps:

    • Log information is written to the memory cache in real time to minimize performance overhead
    • Crontab periodically collects writes from the memory cache to the database or file

Specific algorithm: (Laravel framework)

    • Set a constant: imax=10000000, two variables iwrite=1, iread=1. ( iwrite Log write pointer, iread log read pointer, Iread <=iwrite, two variable values saved in memory cache)
    • For each log generated, use "Cache::increment (iwrite)" To get the increment value of Iwrite, if the value is greater than IMAX, reset to 1, cache the log, key: ' Log_ ' +iwrite, Value: Log content
    • crontab calls the command line every 30 seconds, collects the log, uses "Cache::increment (Iread)" To get the increment value of iread, if it equals iwrite, stops if the value is greater than IMAX, resets to 1, from The cache reads the logs and batches them into the library. Finally , the log is removed from the cache.

The memory cache can be used with APC, XCache, etc.

Cache::increment, which belongs to the Laravel framework built-in method, can be encapsulated if it is not a laravel frame.

Temporarily no time, first record ideas, later have time, practice, and then send out the code.

The above describes the high-performance PHP log scenarios, including aspects of the content, I hope that the PHP tutorial interested in a friend to help.

  • 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.