title: PHP running multiple scripts concurrently
body: <p>I have an array with object server like this:</p>
  
  <pre><code>Array
  (
      [0](
                  (
                      [id] =&gt; 1
                      [version] =&gt; 1
                      [server_addr] =&gt; 192.168.5.210
                      [server_name] =&gt; server1
                  )
          )
      [1](
                  (
                      [id] =&gt; 2
                      [server_addr] =&gt; 192.168.5.211
                      [server_name] =&gt; server2
                  )
          )
  )
  </code></pre>
  
  <p>By running the code below, I'm able to get the desired output</p>
  
  <pre><code>foreach ($model as $server) {
          $cpu_usage = shell_exec('sudo path/to/total_cpu_usage.sh '.$server-&gt;server_addr);
          $memory_usage = shell_exec('sudo path/to/total_memory_usage.sh '.$server-&gt;server_addr);
          $disk_space = shell_exec('sudo path/to/disk_space.sh '.$server-&gt;server_addr);
          $inode_space = shell_exec('sudo path/to/inode_space.sh '.$server-&gt;server_addr);
          $network = shell_exec('sudo path/to/network.sh '.$server-&gt;server_addr);
          exec('sudo path/to/process.sh '.$server-&gt;server_addr, $processString);
          $processArray = array();
          foreach ($processString as $i) {
            $row = explode(" ", preg_replace('/\s+/', ' ', $i));
            array_push($processArray,$row);
          }
          $datetime = shell_exec('sudo path/to/datetime.sh '.$server-&gt;server_addr);
          echo $cpu_usage;
          echo $mem_usage;
          echo $disk_space;
          ......
  }
  </code></pre>
  
  <p>My scripts are similar like:</p>
  
  <pre><code>#!/bin/bash
  if [ "$1" == "" ]
  then
          echo "To start monitor, please provide the server ip:"
          read IP
  else
          IP=$1
  fi
  
  ssh root@$IP "date"
  </code></pre>
  
  <p>But the whole process took like 10 sec for 5 servers compared to 1 server for less than 2 sec. Why is that? Is there anyway to lessen the time? My guess is that the exec command was waiting for the output to be assign to the variable before going to next loop? I tried to google a little bit but most of the answer are for without returning any output at all... I need the output though</p>