记录页面点击详细信息的最有效方法是什么
作为交易的一部分,我们有一个微型网站在全国性报纸上做广告,他们要求以 CSV 或类似形式提供每个页面的以下信息:
- 页面提供时间 页面
- 提供日期
- 提供完整 URL
- 会话 ID
我真的不知道预期的访问者数量,但它可能相当高,所以问题是;最好和最有效的方法是什么?
该网站是静态的,但我可以使用 PHP 或其他。每次提供页面时将这些详细信息添加到 MySQL 数据库是否可能会遇到麻烦?
We have a microsite being advertised in a national newspaper as part of the deal they require the following information for every page served to be provided as CSV or similar:
- Time of page served
- Date of page served
- Full URL served
- Session ID
I really have no idea of the number of visitors expected but it could be fairly high, so the question is; what is the best and most efficient way to do this?
The site is static but I can use PHP or whatever. Am I likely to run into trouble just adding these details to a MySQL database each time a page is served?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在您需要跟踪的每个页面上包含一个通用的 php 文件,并按照您自己的建议在脚本中将详细信息记录到 MySQL。 MySQL 是可扩展的且功能强大的,并且能够处理它,因为它为一些互联网上最繁忙的系统提供支持。
Have a common php file included on every page you need to track and within the script record details to MySQL as you yourself suggest. MySQL is scalable and powerful and will be able to handle it, as it powers some of the internet's busiest sytems.
除非您的用户数量超过一百万,否则您不必担心...
说实话,您可以采取多种方法来监控点击率。这样你就有了几种不同类型的证据!
使用谷歌分析,这是谷歌提供的一些JavaScript代码。这不会显着增加服务器的负载。
创建您自己的代码来获取该数据...您需要帮助来检测每条信息吗?
Unless you're getting over million users you shouldn't have to worry...
To be honest you can do several ways of monitoring the hits. That way you have several different types of proof!
Use google analytics, which is a bit of javascript code provided by google. This won't increase the load on your server by any significant amount.
Create you're own code to pick up that data... do you need help in detecting each piece of information?
您应该使用谷歌分析。
但是,如果您确实需要知道:如果该网站已经使用 PHP,那么您没有理由不能将这些详细信息插入数据库(或添加到 CSV 文件?)。为什么要跟踪会话 ID?
以下是 db 选项的一些示例代码:
You should use Google Analytics.
BUT, if you really need to know: if the site is already in PHP then there's no reason why you can't insert into a db (or add to a CSV file?) these details. Why do you want to track the session id?
Here's some sample code for the db option:
您可以为此使用数据库。并发访问正是它们的用途。但实际上这读起来更像是日志文件的任务。您不再查询这些结果,您只是收集它们。
通常它很简单(假设您不需要转义值):
File_put_contents 是原子的,这就是您希望日志文件不丢失条目的原因。但对于许多并发访问来说,这并不是最优的;进程可能会互相阻塞。因此,您将需要另一个作弊:
这将日志分布在多个文件中; rand() 足以使其平衡。虽然您现在需要再次合并多个文件,但您至少已经拥有正确的格式。
You can use a database for that. Concurrent accesses is what they are made for. But actually this reads more like a task for log files. You are not querying those results ever again, you are just collecting them.
Usually it is as simple as (assuming you need no value escaping):
File_put_contents is atomic, which is what you want for log files to not lose entries. But for many concurrent accesses it is not optimal; processes might block each other. Thus you would need another cheat:
This distributes the logs across multiple files; rand() is enough to even it out. While you now need to merge multiple files again, you at least have it in the right format already.
通过 MySQL 表维护这些数据会很有效,但严格来说可能没有必要,具体取决于您将获得的负载。
或者,您可以考虑使用更轻量级的东西,例如 sqlite。
http://www.sqlite.org/
http://php.net/manual/en/book.sqlite.php
它很好而且有效,需要很少的设置或调整,并且数据库驻留在您服务器上的文件中!
MongoDB 可能是另一个选择,它可以更好地扩展并允许您完全避免 SQL!
我想我得到的是这个,虽然 MySQL 会很好地执行这个任务,但你当然可以做一些不同的、更简单的事情。不过,我确实想对此进行限定,并说一旦您进行大量活动,sqlite 可能会出现一些问题!
Maintaining this data via MySQL table would be efficient, but might not be necessary, strictly speaking, depending on the load you will be getting.
Alternatively, you could consider just using something more lightweight like sqlite.
http://www.sqlite.org/
http://php.net/manual/en/book.sqlite.php
It's nice and effective and requires little setup or tweaking, and database resides in a file on your server!
MongoDB might be another option that will scale much better and allow you to avoid SQL all together!
I guess what I'm getting is this, while MySQL will perform this task very well, you can certainly get away with something different and more simplistic. I do want to qualify this, though, and say that sqlite may have some issues once you get into large amounts of activity!
所需的一切要做的就是在页面底部插入一个很小的 JS 片段:
来自 Stackoverflow 源代码的示例:
注意:不要直接复制此片段,GA 会自动生成您的代码。
All you need to do is inserting a tiny JS snippet to the bottom of your page:
Example from Stackoverflow's source:
Note: Do not copy this snippet directly, GA will generate your code automatically.
嗯,首先,我不知道为什么您想要存储尚未以所需格式存储的所需数据,而是先存储在 SQL 中,然后转换为 CSV。
特别是如果您的网站是静态的,那么,您将需要以某种方式使用 PHP 来完成它。
但是好吧,即使您要使用 PHP,使用 sql 而不是 CSV 对我来说仍然看起来毫无意义。
您的网络服务器很可能已经记录了您需要的几乎所有内容,并且通过较小的调整也将能够记录会话 ID。
因此,如果您的服务器恰好是 Apache,最有效的解决方案就是自定义访问日志, http://httpd.apache.org/docs/current/mod/mod_log_config.html
它会像这样
,只需设置您的 cron 每天通过电子邮件发送此日志
请注意,条件日志记录应该是也用于限制仅记录 html 页面。我从未使用过它,也没有测试过,但根据文档,它可能是
Well, first of all, i have no idea why do you want to store required data not already in desired format but store in in SQL first and then convert to CSV.
Especially if you site is static, so, you will need to employ PHP somehow to do it.
but okay, even if you're gonna employ PHP, using sql instead of CSV still looks nonsense to me.
Your web-server most likely already logs almost everything you need, and with minor tuning will be able to log session id too.
So, if your server happen to be Apache, most efficient solution would be just custom access log, http://httpd.apache.org/docs/current/mod/mod_log_config.html
it's gonna be like
and just set up your cron to send this log by email every day
Please note that conditional logging should be probably used too, to limit logging to html pages only. I never used it nor tested but according to docs it could be