Log to file via PHP or log to MySQL database - which is quicker?

前端 未结 15 1244
故里飘歌
故里飘歌 2021-02-03 11:07

I have a database driven website serving about 50,000 pages.

I want to track each webpage/record hit. I will do this by creating logs, and then batch processing the logs

15条回答
  •  后悔当初
    2021-02-03 11:20

    If you are using either file based logging or database based logging, your biggest performance hit will be file/table locking. Basically, if client A and client B connects within a relatively small time frame, client B is stuck waiting for the lock to be released on the hits file/table before continuing.

    The problem with a file based mechanism is that file locking is essential to ensure that your hits doesn't get corrupted. The only way around that is to implement a queue to do a delayed write to the file.

    With database logging, you can at least do the following [MySQL using MyISAM]:

    INSERT DELAYED INTO `hits` ...
    

    See 12.2.5.2. INSERT DELAYED Syntax for more information.

提交回复
热议问题