Question: I am facing a problem, which, I am sure, lot of others must have faced already.  

How to handle literals in Templates ?  

Please refer my code:

```
template<typename T, typename U>
static void Swap( T& a, U& b )
{
        T temp;
        temp = a;
        a    = (T) b;
        b    = temp;
}

int main()
{
   int i = 10, j = 20;
   //! Working
   Swap<int,int>(i,j);

   int p = 50; double q = 100.0;
   //! Working
   Swap<int,double>(p,q);

  //How to handle this case ?
   Swap<int,int>(5,10);

   return 0;
}

```

Answer: 
Quoting PHP Documentation : 

> 
> 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.
> 
> 
> 

So, you can exec in background if you redirect the output in a file : 

```
exec("../path/to/script.tcl -parameter1 ".$device['param1']." -parameter2 ".$device['param2']." > outputfile.txt", $execout[$devID]);

```

But if you want to wait that ALL execs are finished before continuing, you have to make a call back from the external script. Maybe like this : 

```
exec("../path/to/script.tcl -parameter1 ".$device['param1']." -parameter2 ".$device['param2']." > ../path/to/outputfile.txt; ".PHP_BINDIR.DIRECTORY_SEPARATOR."php ../path/to/callback.php", $execout[$devID]);

```

Like this, your callback.php script will be called after every execs of script.tcl.

Maybe you can do something with these tricks.
Look at ExecFuture andFutureIterator in the libputil library: 

<https://secure.phabricator.com/book/libphutil/class/ExecFuture/>

It does exactly what you need with a pretty nice syntax:

```
$futures = array();
foreach ($files as $file) {
  $futures[$file] = new ExecFuture("gzip %s", $file);
}
foreach (new FutureIterator($futures) as $file => $future) {
  list($err, $stdout, $stderr) = $future->resolve();
  if (!$err) {
    echo "Compressed {$file}...\n";
  } else {
    echo "Failed to compress {$file}!\n";
  }
}

```