-1

I have two php scripts scriptA and scriptB. I am calling scriptB from scriptA. scriptB is called inside a iteration in scriptA But, before scriptB finishes scriptA would have already exited. I am not sure what to do next ? apart from adding delay inside scriptA.

I am calling scriptB inside scriptA

by

foreach (...) {

shell_exec('php -q /path/scriptB.php')

....
}

Thanks !

run_time_rookie
  • 69
  • 1
  • 1
  • 7
  • 1
    Could you clarify the question? How are you currently "calling" scriptB? And what exactly is the problem you're facing? Perhaps you could show us a sample of your code? – IMSoP Sep 26 '13 at 20:10
  • Are you wanting to process output from scriptB in scriptA? – Chris Rasco Sep 26 '13 at 20:14
  • PHP doesn't work that way. When you include/require a file then it's going to execute whatever logic exists in said file before exiting the file that called it. – Ohgodwhy Sep 26 '13 at 20:15
  • Updated how script is being called – run_time_rookie Sep 26 '13 at 20:27
  • ohgodwhy, When I added delay I am getting required result. Hence, main script is getting exited before called script executes and comes back – run_time_rookie Sep 26 '13 at 20:30
  • how are you applying the delay to the code? like this:?http://stackoverflow.com/questions/15414605/php-delay-in-for-loop – Jorge Y. C. Rodriguez Sep 26 '13 at 20:33
  • 1
    I think this question may be suffering from [the XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem): what is it you are actually trying to achieve by wiring together two scripts in this way? – IMSoP Sep 26 '13 at 20:56
  • Also, since `shell_exec` ([as documented here](http://php.net/shell_exec)) returns the output of the executed command, it can't finish until the command it's running finishes, unless you do something wacky with the inner command. – IMSoP Sep 26 '13 at 21:00

2 Answers2

0

I think it depends and you may need to provide more clarification. Here is a simple example that works just fine for me:

A.php:

<?php
    for($i = 0; $i < 10; ++$i) {
        include('B.php');
    }
?>

B.php:

<?php
    echo "The value of \$i is {$i}\n";
?>

When you include a file, the code is included as if it were inline where 'include' is called.

v0rtex
  • 381
  • 3
  • 6
  • If you need to pass command line arguments you will need to do it on the main script being called ('A.php' in this case). Since 'B.php' is being included it will have access to any arguments passed in when the script is invoked (e.g. if invoked as `php A.php -n 3 --arg` 'B.php' can access those arguments just as well as 'A.php'). It might help if you think of it like the code in 'B.php' is directly coded in 'A.php' in place of the _include_ statement because that is exactly what is happening when you include a file. – v0rtex Dec 04 '13 at 01:57
-2

When you call you can like that referenced :

File1 js

function alertNumber(number) {
alert(number); }

File2 js

function alertOne() {
 alertNumber("one"); }

And for synchronization I think, you can use a value that will only change on scriptB, and scriptA will exit only this value change.

Community
  • 1
  • 1
Ozan
  • 1,191
  • 2
  • 16
  • 31