在(PHP、Apache、Nginx)中等待远程入口时释放资源
我的 php 脚本等待远程门响应,通常大约 20 秒。它会导致 apache httpd 线程在打开的 MySQL 连接的情况下驻留在内存中,并最终超过 MaxClients 值。如何管理释放空闲资源直到远程门响应。
一种解决方案是: 1) 运行远程门请求,然后将用户重定向到刷新到某些 url 测试数据到来的页面, 2)在nginx配置文件中写入该url的规则: 如果特定文件存在 然后运行apache给出数据 否则显示刷新页面。 3) 远程gate请求将数据保存在文件中
因此我们从向远程gate发出请求的脚本中取消了apache的链接,并且我们可以使其尽可能小。当远程请求时,服务器仅由该脚本使用,并且来自 nginx 的轻量请求。
所以这可能是一个很好的解决方案,但我想知道这种方法的缺点。也许还有更好的方法。
My php script waits for remote gate response, normally for ~20 seconds. It causes apache httpd threads to live in memory with opened MySQL connection and finally to exceed MaxClients value. How it can be managed to free idle resources until remote gate reponse.
One solution is:
1) run remote gate request and then redirect user to page that refreshes to certain url testing for data coming,
2) write rule for that url in nginx configuration file:
if specific file exist
then run apache to give data
else show refreshing page.
3) remote gate request saves data in file
Therefore we unlinked apache from the script that makes request to remote gate and we can make it tiny as possible. While remote request, server used only by that script and light requests from nginx.
So it may be good solution, but I would like to know downsides of this approach. And may be there are better ways.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您可以在等待远程门响应时关闭 MySQL 连接。
然后在收到响应后重新打开它:
如果您仅在远程门响应之前或之后需要 MySQL 连接,我建议仅在正确位置建立一次 MySQL 连接。
一般来说 mysql_connect() 有点昂贵。
但与您的响应所需的 20 秒相比,这绝对是便宜的。
Well, you could close your MySQL-connection while waiting for the remote gates response.
And then reopen it once you got the response:
If you need the MySQL connection only before or only after the remote gate response, I would suggest establishing the MySQL connection only once at the correct possition.
In general mysql_connect() is a little expensive.
But compared to the 20sec your response needs, this is definitely inexpensive.