Doing PHP timeouts so they don't kill my server

The reason is probably that I ran out of disk space, causing everything to work strangely. I'll leave this question anyway in case anyone else has a similar problem.

I have a few PHP scripts that have been hanging for a long time, but apparently they don't actually use up a lot of CPU time as they don't get killed. However, they make it impossible for lighttpd to spawn more PHP processes since the maximum number of them has already been created.

I know that set_time_limit can be used as a function or put in php.ini to control the maximum cpu time a script can run. I want to limit all PHP scripts executed by my web server (lighttpd) not in CPU time, but in hours.

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 for a lot longer than I expected and has caused a server clog. Strangely, there also seems to be more PHP processes 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 )
204.16.33.46    0/0 0/0 handle-req  1420    ... (another PHP )
... gazillion lines removed ...

      

Any ideas that could help me set up a config that I don't have to babysit all the time would be greatly appreciated!

0


source to share


2 answers


Your best bet is probably to edit your php.ini file and set the 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)

      

+1


source


I'm not sure if you can do this in lighttpd. However, you can configure a "spinner" script to periodically check for hung processes and kill them.



+1


source







All Articles