exec()
我的腳本中有五個函數。我想對其進行設置,以便如果某個函數在給定時間內未能響應,該函數將被終止,下一個函數將開始執行。
<?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);
?>
在這一點上,這個timeout
論點是行不通的。請糾正這個問題或給我一個替代方法。
答案1
你的 exec sysntax 是錯誤的
string exec ( string $command [, array &$output [, int &$return_var ]] )
在開始編寫程式碼之前,您必須設定時間限制,如下所示
<?php
set_time_limit(5);
exec(" /usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
?>