A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearMaking PHP scripts time out so they don't kill my server - page 1
User InfoPosts
Making PHP scripts time out so they don't kill my server#1
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.

. = 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

Client IP: Read: Written: State: Time: Host: URI: File: 0/0 0/0 handle-req 1361 ... (a PHP script) 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!

posted date: 2008-12-17 07:12:00

Re: Making PHP scripts time out so they don't kill my server#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-17 07:12:01

Re: Making PHP scripts time out so they don't kill my server#3
Shouldn't you be more worried why these PHP scripts are taking so long to return? That sounds like a serious bug.

posted date: 2008-12-17 07:20:00

Re: Making PHP scripts time out so they don't kill my server#4
There can always be bugs in scripts, and I would just like to make sure that even if I leave my scripts running for a year while I go to Mars, things would be still working when I come back regardless.

posted date: 2008-12-17 07:22:00

Re: Making PHP scripts time out so they don't kill my server#5
@Bemmu: If the scripts are well written there is no issue and everything does it's job. You are basically asking to make your car crash proof because you have no traction. You are addressing the wrong issue.

posted date: 2008-12-17 07:26:00

Re: Making PHP scripts time out so they don't kill my server#6
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.

posted date: 2008-12-17 07:33:00

Re: Making PHP scripts time out so they don't kill my server#7
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 secondsmax_input_time = 60 ; Maximum amount of time each script may spend parsing request datamemory_limit = 32M ; Maximum amount of memory a script may consume (8MB)

posted date: 2008-12-17 07:40:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.