I am testing a php script that has been developed on an OS-X system at Debian and it behaves different there.
To reproduce it I wrote two scripts: parent.php and child.php:
parent.php:
#!/usr/bin/php
<?php
echo "parent started...\n";
shell_exec(__DIR__ . '/child.php &2>/dev/null &');
echo "parent finished.\n";
child.php:
#!/usr/bin/php
<?php
echo "child started...\n";
sleep(5);
echo "child finished.\n";
Running parent.php on OS-X I get back imediately the two output lines (parent started, parent finished). On Debian I get the “parent started…” line, then a delay of 5 seconds an then the “parent finished.”. Running “./child.php &2>/dev/null &” in the shell gives me back the prompt imediately as expected. Any ideas how I can fix this?
This is because
&2>part. It may not be supported in all systems. Also in every shell (bash, sh, ksh etc).Try this,
If you want to suppress all the output use this,
BASH-HOWTO
Just tested,
exec("/usr/bin/php /path/to/child.php > /dev/null 2>&1 &")should work too.