php的exec执行后台进程会堵塞,卡到子进程结束才结束

贵贵的博客 ( http://blog.linuxphp.org/ ) : php入口执行一个shell
<?php 
$a = exec("./a.sh");
var_dump($a);
  看下a.sh 的内容
#!/bin/bash
echo "11"
(sleep 10) &
shell的sleep是后台执行的,php执行shell,php会卡住等到10s才结束,为什么?   --- 经过朋友的提醒发现要把sleep的输出重定向到 /dev/null 修改后脚本如下
#!/bin/bash
echo "11"
(sleep 10 > /dev/null) &
  官方也有给相关的说明,只是在很不起眼的Note 

Note:

If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

 

文章来源:

Author:linuxphp@qq.com(keminar)
link:http://blog.linuxphp.org/archives/1651/