让 PHP 脚本超时,这样它们就不会杀死我的服务器

发布于 2024-07-10 16:02:56 字数 1588 浏览 5 评论 0原文

原因可能是我的磁盘空间不足,导致一切工作异常。 无论如何,我都会保留这个问题,以防其他人遇到类似的问题。

我有一些 PHP 脚本已经挂了很长时间,但显然它们并没有真正使用太多的 CPU 时间,因为它们没有得到被杀了。 尽管如此,它们仍然使 lighttpd 无法生成更多 PHP 进程,因为它们已经生成了最大数量。

我知道 set_time_limit 可以用作函数或放入 php.ini 中来控制脚本可以运行的最大 CPU 时间。 我想要的是限制我的网络服务器(lighttpd)运行的所有 PHP 脚本不是 CPU 时间,而是时钟时间。

如果重要的话,这是我的 lighttpd 配置文件中的 PHP 部分。

fastcgi.server = (".php" => ((
 "bin-path" => "/opt/local/bin/php5-cgi",
 "socket" => "/tmp/php.socket" + var.PID,
 "min-procs" => 16,
 "max-procs" => 16,
 "idle-timeout" => 15,
)))

这是我来自 lighttpd 的服务器状态。 您可以看到 PHP 的运行时间比我预期的要长得多,并导致服务器堵塞。 奇怪的是,PHP 进程似乎比我的最大进程还要多。

legend
. = connect, C = close, E = hard error
r = read, R = read-POST, W = write, h = handle-request
q = request-start,  Q = request-end
s = response-start, S = response-end
388 connections
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhrhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhhhhhhhhhhhrhhhhhhhhhhhhhhhhhhhhhhhhrhhhhhhhhhhh
hhhhrhhhhhhhhhhrhrhhhrrhrhhhhhrhhhrhhhhhhrhhhrrrhr
rrhrrrhrhhhhrrhrrhhrrhrrhrrrrrrrrrrrrh

Connections
Client IP:  Read:   Written:    State:  Time:   Host:   URI:    File:
204.16.33.51    0/0 0/0 handle-req  1361    ... (a PHP script)
204.16.33.46    0/0 0/0 handle-req  1420    ... (another PHP script)
... gazillion lines removed ...

任何可以帮助我设置一个配置,让我不必经常照顾的想法将不胜感激!

The cause was probably that I ran out of disk space, causing everything to work strangely. I will leave this question up anyways in case anyone else has a similar issue.

I have a few PHP scripts that have hung for a long time, but apparently they are not really using much CPU time as they don't get killed. Still they are making it impossible for lighttpd to spawn any more PHP processes as the maximum amount of them has been spawned already.

I'm aware of the set_time_limit that can be used as a function or put into php.ini to control the maximum CPU time a script can run. What I want is to limit all PHP scripts run by my web server (lighttpd) not in CPU time, but clock time.

In case it matters, this is the PHP part from my lighttpd config file.

fastcgi.server = (".php" => ((
 "bin-path" => "/opt/local/bin/php5-cgi",
 "socket" => "/tmp/php.socket" + var.PID,
 "min-procs" => 16,
 "max-procs" => 16,
 "idle-timeout" => 15,
)))

Here is my server-status from lighttpd. You can see that PHP has been running much longer than I bargained for and has caused the server to clog up. Strangely there also seem to be more PHP procs than my max-procs.

legend
. = connect, C = close, E = hard error
r = read, R = read-POST, W = write, h = handle-request
q = request-start,  Q = request-end
s = response-start, S = response-end
388 connections
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhrhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hhhhhhhhhhhhhrhhhhhhhhhhhhhhhhhhhhhhhhrhhhhhhhhhhh
hhhhrhhhhhhhhhhrhrhhhrrhrhhhhhrhhhrhhhhhhrhhhrrrhr
rrhrrrhrhhhhrrhrrhhrrhrrhrrrrrrrrrrrrh

Connections
Client IP:  Read:   Written:    State:  Time:   Host:   URI:    File:
204.16.33.51    0/0 0/0 handle-req  1361    ... (a PHP script)
204.16.33.46    0/0 0/0 handle-req  1420    ... (another PHP script)
... gazillion lines removed ...

Any ideas that could help me set up a configuration that I don't have to constantly babysit would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

樱&纷飞 2024-07-17 16:02:56

您可能最好编辑 php.ini 文件并在那里设置权限。

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 32M      ; Maximum amount of memory a script may consume (8MB)

You're probably best off editing the php.ini file and setting permissions there.

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 32M      ; Maximum amount of memory a script may consume (8MB)
困倦 2024-07-17 16:02:56

我不确定你能在 lighttpd 中做到这一点。 但是,您可以设置一个“spinner”脚本来定期检查挂起的进程并终止它们。

I'm not sure you can do that in lighttpd. You could, however, set up a "spinner" script to periodically check for hung processes and kill them.

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