pcntl_fork() and apache , redirect to stdout

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I'm trying to run a system call('ls' in this simple case) that is taking  
quite a long. I would like to fork the system call into a child process  
and waits display the output of the call while it is running.

Here is a piece of code:

$pid = pcntl_fork();

for ($i = 1; $i <= 5; ++$i) {
         $pid = pcntl_fork();

         if (!$pid) {
             $query = "ls /tmp";
             system ($query,$ret_val);
         print "In child $i\n";

How can i make this script dynamic in my web page. Meaning how can i  
print each loop while the child process is running in Apache and  
redirect to STDOUT in the webpage???

Site Timeline