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

前端 未结 15 1226
故里飘歌
故里飘歌 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:26

    A few considerations:

    1. Do you think you'll want to join log data with other data in the database? If so, the overhead of a db insert is likely justified so existing relationships can be easily leveraged.
    2. Would logging the data in the database allow you to reduce the amount of data you're logging greatly (due to existing relationships in the db)? For example, a log in the database of user activity could simply be a table containing a userid, activityid, and a timestamp. A log file this lean in a file wouldn't be human readable. Depending on your needs, you'd need to capture at least some of the user's data in the log file to assure it can be useful and human readable on its own.
    3. Any chance you'll want to leverage this log data in the front end or via an admin tool down the road? If so, DB write is likely preferable.
    0 讨论(0)
  • 2021-02-03 11:27

    I'd recommend you test both with a few test cases.

    I would assume a flat file would be faster, b/c that's really what the DB is doing - it's just writing it to a file. The only advantage I can think of is if the database can run concurrently, you might get better results.

    0 讨论(0)
  • 2021-02-03 11:37

    I would believe that a flat file will be faster to write to.

    0 讨论(0)
提交回复
热议问题