0

I have this sample code called main.php:

<?php
shell_exec('C:\wamp\bin\php\php5.4.3\php.exe a.php');
shell_exec('C:\wamp\bin\php\php5.4.3\php.exe b.php');
?>

when execute this script after executing first shell_exec it staying until finishing first shell_exec and then run second.

but I want that script dont stay for finishing first shell_exec and its output and runs second.

now how can I do this?

I have several scripts and I need to run them Simultaneously by a main script and control them by it. but I dont know that how to run my scripts Simultaneously from inside of this main script?

update1: I cant run a.php and b.php by cron jobs because their finishing time is unknown. maybe a.php finished after 1 hour or 10 minutes and b.php as same as a.php too.

update2: I founded a solution in this page:

Is there a way to use shell_exec without waiting for the command to complete?

Community
  • 1
  • 1
saeid ezzati
  • 199
  • 1
  • 3
  • 16
  • what is the use-case? Possible solutions would include ajax or for example scheduled jobs if it's just something that needs to run periodically. – jeroen Jul 23 '13 at 01:14
  • I dont run these scripts by browser. these scripts must run in background – saeid ezzati Jul 23 '13 at 01:25
  • If you are looking for a shell script, check this question: http://stackoverflow.com/questions/672719/parallel-execution-of-shell-processes – jeroen Jul 23 '13 at 01:28
  • @jeroen I dont understand them. I only want a simple way to run an cmd command from inside of a php script and dont stay for its output and execute rest of my script codes :( – saeid ezzati Jul 23 '13 at 01:40
  • Duplicate of http://stackoverflow.com/questions/7657846/executing-a-shell-script-in-background-with-php . – Coroos Jul 23 '13 at 08:21

1 Answers1

1

If i understand you wish to run a background process on a Windows box.Suggest try this...

<?php
    shell_exec('start /b C:\wamp\bin\php\php5.4.3\php.exe a.php');
    shell_exec('start /b C:\wamp\bin\php\php5.4.3\php.exe b.php');
?>
pradosh nair
  • 800
  • 1
  • 14
  • 23