Convert's max execution time
Posted: 2008-02-19T05:40:38-07:00
Hello everyone.
I know this is not strictly an Imagemagick related question, but hopefully someone can help or suggest some hint anyhow.
And sorry in advance for my english, i am Italian
I created a PHP application to generate images, using convert via PHP exec() function.
OS is a linux box, Fedora core 6.
Sometimes it may happen that heavy paramenters are sent to it, requesting a very big and huge process.
It happened that, using "top" i found a convert process running from more than 5 hours!
The result of that was a whole server slowdown.
Considering that after such amount of time the requesting user would surely not be there waiting for the result, i wanted to limit convert max execution time, IE "kill convert if it is running from more than 5 mins".
I tried using shell_exec to run the command and get the pid, then using ps to check if the script is still running, but this silly solution is even worst, as it calls ps hundreds of times.
Do you have any hints on how i may run convert setting a max execution time for it?
Every way would be fine: controlling it via PHP, or using some linux program to launch convert itself.
The dream would probably be a small program in C being something like:
time_controlled_exec(cmd_to_execute,max_exec_time)
But i wasn't able to find any, and i'm not able to write one by myself.
Any hint will be very appreciated, thanks in advance!
I know this is not strictly an Imagemagick related question, but hopefully someone can help or suggest some hint anyhow.
And sorry in advance for my english, i am Italian
I created a PHP application to generate images, using convert via PHP exec() function.
OS is a linux box, Fedora core 6.
Sometimes it may happen that heavy paramenters are sent to it, requesting a very big and huge process.
It happened that, using "top" i found a convert process running from more than 5 hours!
The result of that was a whole server slowdown.
Considering that after such amount of time the requesting user would surely not be there waiting for the result, i wanted to limit convert max execution time, IE "kill convert if it is running from more than 5 mins".
I tried using shell_exec to run the command and get the pid, then using ps to check if the script is still running, but this silly solution is even worst, as it calls ps hundreds of times.
Do you have any hints on how i may run convert setting a max execution time for it?
Every way would be fine: controlling it via PHP, or using some linux program to launch convert itself.
The dream would probably be a small program in C being something like:
time_controlled_exec(cmd_to_execute,max_exec_time)
But i wasn't able to find any, and i'm not able to write one by myself.
Any hint will be very appreciated, thanks in advance!