Rectangle 27 0

php Call a .phar executable from inside a web app controller?

class Maintenance_Controller

    public function do_maintenance()
        exec("composer.phar update", $out, $ret);
        if(!$ret) {
            // handle success
        } else {
           // handle error


Did you try with the full path to php instead of executing through env?

I think you can use PHP_BINDIR for the full path. Not sure which versions that covers though.

Im not sure why you are using passthru here. I would use exec for better handling. Id use exec here instead of passthru

This way you have all the output by line in $out as well as the shell return val (0 if ok, > 0 if not). If you wanna get really fancy you can loop over $out and scan for the errors and then build and exception to throw.

Try using exec('php composer.phar', $out, $ret); and see if that works. You might also need to use the full path to php if its in a non-standard location which you can probably get from which php.

Value 127 is returned by /bin/sh when the given command is not found within your PATH system variable and it is not a built-in shell command.