在(PHP、Apache、Nginx)中等待远程入口时释放资源

发布于 2024-09-10 22:26:24 字数 393 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心凉 2024-09-17 22:26:25

好吧,您可以在等待远程门响应时关闭 MySQL 连接。

mysql_close($link);

然后在收到响应后重新打开它:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

如果您仅在远程门响应之前或之后需要 MySQL 连接,我建议仅在正确位置建立一次 MySQL 连接。

一般来说 mysql_connect() 有点昂贵。
但与您的响应所需的 20 秒相比,这绝对是便宜的。

Well, you could close your MySQL-connection while waiting for the remote gates response.

mysql_close($link);

And then reopen it once you got the response:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文