The script:
$S = 'pgrep -f test.php | wc -l';
$U = trim(shell_exec($S));
echo $U;
Why is the result of this script equal to 0
and sometimes 1
?
The file test.php
is not running.
The script:
$S = 'pgrep -f test.php | wc -l';
$U = trim(shell_exec($S));
echo $U;
Why is the result of this script equal to 0
and sometimes 1
?
The file test.php
is not running.
The problem is while executing the command pgrep -f test.php | wc -l
, it will show up itself sometimes (depending on the timing) in the results. You can prevent that according to a question on Linux & Unix SE using the following syntax:
pgrep -f '[t]est.php' | wc -l
The part with the brackets basically says "find the letter t followed by est.php", which will find the file if it is running, but will not match the currently executed command, because after the t
follows a bracket [
.