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.
我的脚本中有五个exec()函数。我想如果任何函数在给定时间内不给出任何响应函数将kill,然后下一个函数开始执行。
<?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.
在此超时参数不起作用。请更正此或提供任何替代方法。
1 个解决方案
#1
1
Create a bash script caller.sh and execute it via exec. The command will be automatically killed after 5 seconds.
创建一个bash脚本caller.sh并通过exec执行它。该命令将在5秒后自动终止。
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);
#1
1
Create a bash script caller.sh and execute it via exec. The command will be automatically killed after 5 seconds.
创建一个bash脚本caller.sh并通过exec执行它。该命令将在5秒后自动终止。
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);