Reputation: 514
I have five exec()
function in my script.I want if any function will not give any response in given time function will kill and then next function starts its execution.
<?php
exec("timeout 5 /usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
exec("timeout 5 /usr/local/bin/trun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
exec("timeout 5 /usr/local/bin/drun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
?>
In this timeout
argument not working.Please correct this or gives any alternative method.
Upvotes: 1
Views: 1079
Reputation: 9979
Create a bash script caller.sh and execute it via exec. The command will be automatically killed after 5 seconds.
caller.sh
#!/bin/sh
/usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat' &
sleep 5
kill $! 2>/dev/null && echo "Killed command on time out"
PHP
exec("caller.sh",$uptime);
Upvotes: 1