在 php 中执行 bash if else 命令(bash vs php)
execute bash if else command in php ( bash vs php )
我想达到的目标
我想执行一些脚本,它的进程未在服务器上启动。为此,我正在 shell 脚本中准备命令并在单行中执行它。
带有 php 变量的命令
$cmd = "if [[ `ps auxww | grep -v grep | grep ".$process_file." | grep '".$find."'` == '' ]] ; then ".$cmd2." fi";
echo $cmd."\n";
执行的命令,一旦变量被替换(实际上 运行 在 bash 上):
if [[ `ps auxww | grep -v grep | grep /home/new_jig.php | grep 'test_51 1714052'` == '' ]] ; then php /home/new_jig.php test_51 1714052 & fi;
正在执行命令
exec($cmd,$out,$res);
请注意,我还将问题拆分为两个语句并执行它们。但这很耗时。当我的列表中有超过 2000 个时,它会导致问题,并且对所有命令执行。这需要大约 1 分钟或超过 1 分钟才能到达最后一个数字。
我想在 10 秒内完成。请帮助我达到最佳输出。
谢谢
吉涅什
我可以用下面的命令让它执行
$process_file = 执行某些功能的 phpfile
$cmd2 = " php ".$process_file." 1212 >/dev/null 2>/dev/null &
";
$cmd11 ="if ps -auxw | grep -v grep | grep '".$process_file."' | grep '".$find."' &> /dev/null
; then echo 1;".$cmd2."; fi";
shell_exec($cmd11." >/dev/null 2>/dev/null &");
在此之前:对于 1100 个请求,该过程大约需要 60+ 秒
此后:它在 20 到 30 秒
之间完成
我想达到的目标 我想执行一些脚本,它的进程未在服务器上启动。为此,我正在 shell 脚本中准备命令并在单行中执行它。
带有 php 变量的命令
$cmd = "if [[ `ps auxww | grep -v grep | grep ".$process_file." | grep '".$find."'` == '' ]] ; then ".$cmd2." fi";
echo $cmd."\n";
执行的命令,一旦变量被替换(实际上 运行 在 bash 上):
if [[ `ps auxww | grep -v grep | grep /home/new_jig.php | grep 'test_51 1714052'` == '' ]] ; then php /home/new_jig.php test_51 1714052 & fi;
正在执行命令
exec($cmd,$out,$res);
请注意,我还将问题拆分为两个语句并执行它们。但这很耗时。当我的列表中有超过 2000 个时,它会导致问题,并且对所有命令执行。这需要大约 1 分钟或超过 1 分钟才能到达最后一个数字。
我想在 10 秒内完成。请帮助我达到最佳输出。
谢谢 吉涅什
我可以用下面的命令让它执行
$process_file = 执行某些功能的 phpfile
$cmd2 = " php ".$process_file." 1212 >/dev/null 2>/dev/null &
";
$cmd11 ="if ps -auxw | grep -v grep | grep '".$process_file."' | grep '".$find."' &> /dev/null
; then echo 1;".$cmd2."; fi";
shell_exec($cmd11." >/dev/null 2>/dev/null &");
在此之前:对于 1100 个请求,该过程大约需要 60+ 秒 此后:它在 20 到 30 秒
之间完成