PHP system() - return status is always 0
You might want to check if it's calling the right php executable on th Unix machine. On many UNIX systems you would need to call the php-cli executable insted of the php one for use on the command line.Another thing to check would be permissions. Maybe the user executing the script_b.php script doesn't have permissions to execute script_a?
Try making the PHP system
call with the absolute path of both the PHP executable and the script filename, e.g.: system('/usr/bin/php /path/to/script_a.php', $return);
. Maybe it's a path issue. (You may find the absolute path of your PHP executable with: which php
).
Also, as someone suggested, try debugging the actual return value of script_a.php on your UNIX server by running php script_a.php; echo $?
on the command line. That echo
will output the last return value, i.e., the value returned by script_a.php.
Anyway, I suggest doing an include
with a return
statement as described in Example #5 of the include() documentation. If you can adapt your scripts like this, it's a more efficient way of communicating them.
// File: script_a.php<?php return 1; ?>// File: script_b.php<?php $return = (include 'script_a.php'); var_dump($return);?>