I want to limit the php-cgi processes time since the processes never
close themselves and slowly all those processes eat the whole RAM (not
cache/buffer) and the server starts going very slow. The only way
right now to close those processes is using CSF and killing the
processes exceeding more than 300 seconds, for example.
I am looking at this solution too and the problem is also with CPU usage, but couldn't found anything about time limitation at least termitation hanging process except
max_execution_time: This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server
max_input_time: This sets the maximum time in seconds a script is allowed to parse input data, like POST, GET and file uploads.
Php-cgi is like rendering all the code you put on the server, it must be the code is compleks or maybe something abuse it like DDos spam that make it read your code heavyly.
Using that I found processes which ran more than 345600 seconds. I
tried everything in config files and nothing works.
The only way to stoping process forcefully is from the server side using like killall -9, not found any service to do that yet.
From the apache configuration part, you just can using IfModule prefork.c for limiting the connection or request per child process on apache.