使用PHP终止shell脚本


Terminate shell script using PHP

我正试图使用PHP代码终止一个shell脚本。

我创建了一个shell脚本foo.sh,它调用一个PHP文件

#! /bin/bash
cd /var/www/html/test
php test.php

以下是test.php

<?php
  exec('exit 0');
?>

由于某些原因,shell脚本没有退出。

您在PHP中的exit(0)将使用PHP本身终止进程,而不是父进程(如果有的话)。要终止bash脚本,您需要通过psgrep找到它的pid,或者使用killall:

system('killall foo.sh');

-在PHP 中