6

I'm running an enterprise level PHP application. It's a browser game with thousands of users online on an infrastructure that my boss refuses to upgrade and the machinery is running on 2-3 system load (yep linux) at all times. Anyhow that's not the real issue. The real issue is that some users wait until the server gets loaded (prime time) and they bring their mouse clickers and they click the same submit button like 10 - 20 times, sending 10-20 requests at the same time while the server is still producing the initial request, thus not updated the cache and the database.

Currently I have an output variable on each request, which is valid for 2 minutes and I have "mutex" lock which is basically a flag inside memcache which if found blocks the execution of the script further, but the mouse clicker makes so many requests at the same time that they run almost simultaneously which is a big issue for me.

How are you, the majority of StackOverflow folks dealing with this issue. I was thinking of flagging the cookie/session but I think I will get in the same issue if the server gets overloaded. Optimization is impossible, the source is 7 years old and is quite optimized, with no queries on most pages (running off of cache) and only querying the database on certain user input, like the one I'm trying to prevent.

Yep it's procedural code with no real objects. Machines run PHP 5 but the code itself is more of a PHP 4. I know, I know it's old and stuff but we can't spare the resource of rewriting this whole mess since most of the original developers left that know how stuff is intertwined and yeah, I'm basically patching old holes. But as far as I know this is a general issue on loaded PHP websites.

P.S: Disabling the button with javascript on submit is not an option. The real cheaters are advanced users. One of them had written a bot clicker and packed it as a Google Chrome extension. Don't ask how I dealt with that.

4

4 回答 4

1

我感觉这更多地涉及如何更新遗留代码库,而不是其他任何事情。虽然实现某种类型的并发会很好,但旧代码库是您真正的问题。

我强烈推荐这个讨论技术债务的视频。

观看它,如果您还没有,请用业务术语向您的老板解释什么是技术债务。他很可能会明白这一点。说明由于代码管理不善(债务偿还),技术债务水平非常高。向他/她建议如何通过使用小的增量迭代来改进事情来解决这个问题。

于 2014-01-23T21:38:25.457 回答
1

我会在您的代码之外寻找解决方案。

不知道您使用哪个服务器,但 apache 有一些模块,例如 mod_evasive。

您还可以限制防火墙中 IP 的每秒连接数

于 2013-05-29T13:53:23.597 回答
0

限制IP连接只会让你的玩家生气。我用旧式代码修复并重写了一些著名的开源游戏克隆中的很多东西:嗯,我必须说,作弊总是可以避免执行正确的查询和逻辑。例如看这里http://www.xgproyect.net/2-9-x-fixes/9407-2-9-9-cheat-buildings-page.html

无论如何,关于性能,请记住会话内的代码将阻塞所有其他线程,直到当前线程关闭。因此,请小心将所有代码包含在会话中。此外,会话不应包含大量数据。

关于脚本:在我的游戏中,我有一个 php 模块,它自动重写链接,添加一个保存在数据库中的随机 id,一种 CSRF 保护。人类用户将单击更改的链接,因此他们将看不到更改,但脚本会尝试询问旧链接,并且在尝试后被禁止!其他脚本使用 DOM ,因此很容易避免它们在页面周围插入一些无用的 DIV。

编辑:您可以使用https://github.com/facebook/hiphop-php/wiki提升您的应用程序

于 2013-09-13T10:48:51.710 回答
0

我不知道是否已经有一个实现,但我正在考虑编写一个缓存服务器,它负责在缓存未命中时填充自己。这种方法在这种情况下可以很好地工作。

基本上,您需要一种机制来将缓存槽标记为未命中挂起;读取挂起的值应该导致客户端休眠一小段但随机的时间并重试;传统模型中待处理数据的填充将由遇到未命中而不是待处理的客户端完成。

在这种情况下,脚本是客户端,而不是浏览器。

于 2016-03-12T11:53:02.400 回答