I have a php script that perform some actions after killing some old processes.
act.php
$pids = shell_exec('ps aux | grep "saso" | awk \'{print $2}\'');
$pids = str_replace("\n", ' ', $pids);
$pids = array_filter(explode(' ', $pids));
foreach ($pids as $pid) {
shell_exec('kill -9 ' . $pid . ' > /dev/null 2>&1 &');
}
// reset of the code . ..
The script works well by running php act.php
. It fetch process ids, kill it, then run the rest.
But it is not working when I run nohup php act.php &
or nohup php act.php
. The process is not killed.
I need nohup
to run the script in the background with no hang up.
Can't PHP script fetch pids behind nohup
? and are there any alternatives?
Thanks in advance.
If you search properly, you can find the result .
Try:
$output = shell_exec('/usr/bin/nohup php script.php >/dev/null 2>&1 &');
Or:
exec('/usr/bin/nohup php script.php >/dev/null 2>&1 &');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.