Title: Exec within a for loop - execute multiple instances
Tags: php
Question: How can you run multiple exec instances from a for loop and run them separately (i.e. not have one dependent on another finishing before starting another)? I have the following code which is hopefully self explanatory:
for ($i = 0;$i < 5;$i++){
exec('START '.$path.' '.PATH.'spawn.php "'."$type,$core".'"');
I have looked at php in background exec() function but it isn't a duplicate as I am using the START command and adding an &amp; did not fix it.
I have tried /B as an option but additionally this didn't work - it just ran it in the background.
Comment: What OS are you using?

Comment: Okey the reason the & did not work is because that's for a Unix OS. Do you want the processes the run in parallel or one after the other?

Comment: Windows 2008 R2 SP1 :)

Comment: All at the same time - in parallel. Is that possible?

Here is the accepted answer: Under windows you will need to do it a bit differently.
$runCommand = 'calc.exe';
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell-&gt;Run($runCommand, 7, false);
This should help explain it http://www.somacon.com/p395.php
http://de2.php.net/manual/en/function.exec.php#43917
Comment for this answer: Brilliant. Although I still need to tweak my code WScript.Shell through COM worked great. Thanks


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:09/02/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php>', 'Title': 'Exec within a for loop - execute multiple instances', 'ViewCount': 226, 'id': 32356454, 'user_AboutMe': '<p>PHP web application developer</p>\n', 'user_AccountId': 4266217.0, 'user_DisplayName': 'Ukuser32', 'user_Reputation': 2069.0, 'user_Views': 220.0, 'user_id': 3489279.0}}