php 横幅队列 fifo
我刚刚开始在我的网站上投放广告,我希望能够为 ad_a 提供 1000 次浏览,为 ad_b 提供 2000 次浏览,假设为 ad_c 提供 10000 次浏览。
如果当时仅查看一个页面,则可以轻松更新数据库并计算出每个广告还剩多少个页面可供查看,但可以同时访问多个页面,这会使事情变得更加复杂。
我正在考虑写一个队列来管理它,请求将在数据库上一一完成。我不确定这是否是最好的想法,从来没有做过这种编码,我正在寻找一系列行为、逻辑步骤、如果有规范的话在数据库中创建什么样的表。
非常感谢您的帮助!
I'm just starting to put ad on my website and I would like to be able to give 1000 view to ad_a , 2000 to ad_b and let say 10000 to ad_c.
If only one page was view at the time it would be easy to update a DB and work out how many are left to view for each ad, but serval pages can be access at the same time and this make things more complicated.
I was thinking of writting a queue to manage it and request will be done one by one on the database. I'm not sure if this is the best idea or not, never done this kind of coding and I'm looking for a line of conduct, logical steps, what kind of table to create in the db if there is specification.
Many thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Memcached 来存储当前的浏览次数。 Memcached 快速且轻便,您不会遇到性能问题。另外,更复杂的事情是有一个“队列”,正如你所说,一些并行进程会更新它,放入要显示的横幅,这样你就可以将它们混合起来。
You could use Memcached to store the current count of views. Memcached is fast and light, you will not have performance problems. Also, something more complicated would be to have a "queue", as you say, and some parallel process updates it putting in there what banner to show, so you could mix them up.
事实上,一个页面可以被多次查看并不一定是一个问题,这就是为什么锁定表 的用途。
这样,在更新之前没有人可以读取该表。
(这个例子是针对 MySQL 的,我确信大多数其他 RDBMS 也支持锁)
The fact that one page may be viewed many times at once doesn't have to be a problem, that's why LOCK TABLES is for.
This way no one can read the table until it's updated.
(this example is for MySQL, I'm sure that most other RDBMSs support locks as well)
兰特呢?
What about rand?