0

Different from the other situations I found here on SO

I have the following code in the main php script

include("sql.php"); //holds all the data to mysql (and variable $db to connect)

$output = shell_exec('/usr/local/bin/php folder/another_script.php')

and in another_script.php I have this:

include_once("../sql.php"); //notice difference to previous include in the other script

$query = "some query";
$db->query($query)

$output in the first script is blank. The second script runs when alone and not called from another script. What am I missing?

2
  • 1
    Why would you do this? Commented Aug 14, 2015 at 11:33
  • @BartFriederichs for some reason, I'm sure, else I wouldn't be asking... That's not important. The point is I am asking why this won't work this way. I don't want to run it by a different code structure. Commented Aug 14, 2015 at 12:57

1 Answer 1

2

The documentation says:

Execute command via shell and return the complete output as a string

It returns the output. You never use the output, hence nothing is shown. You could do this:

$output = shell_exec('/usr/local/bin/php folder/another_script.php')
echo $output;

Yet, I advise you to reconsider your design to create classes or functions to separate functionality instead of calling (quite expensive) shells to call PHP code.

Sign up to request clarification or add additional context in comments.

3 Comments

I echo the output. Nothing is shown. This is called as soon as my server starts. No problem in performance.
none. I only get an error when I change the path and get "could not open/find file xxx/another_script.php". Since I get nothing like this I'm assuming it is correct...
so, no idea? I really can't figure it out at all, do you think of anything that might be off? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.