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

前端 未结 15 1245
故里飘歌
故里飘歌 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.

提交回复
热议问题