通过PHP登录到文件或登录到MySQL数据库-哪个更快?

问题描述:

我有一个数据库驱动的网站,提供大约50,000个页面.

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 once a day. I am not concerned with how I will do the batch process, only with the quickest way to log.

您如何登录,您认为登录更快?

How would you log, which do you think is quicker:

a)使用PHP附加到文本日志文件的末尾.

a) Use PHP to append to the end of a text log file.

b)使用MySQL插入未索引的日志表.

b) Use MySQL to INSERT INTO a non-indexed log table.

  1. 写入文件.轮换日志.

  1. Write to file. Rotate logs.

批处理将文件加载到数据库

Batch load the file to the database on a scheduled basis.

选择这种体系结构的原因有很多–易于扩展(写入许多日志,将它们加载到db),不依赖数据库中的SPOF(如果出了问题,您只需累积日志即可)一段时间),能够在加载时进行清理和非平凡的解析,而不会给您的生产服务器造成负担,等等.

There are many, many reasons to choose this architecture -- ease of scaling (write to many logs, load them to db), lack of reliance on a SPOF in the database (if something goes wrong, you just accumulate logs for a while), ability to do cleaning and non-trivial parsing at load-time without burdening your production servers, and more.