0

I have a simple test case setup like so:

exec('/path/to/bash/script', $output, $return);

That piece of code successfully launches a bash script, which contains the following:

#!/usr/bin/env bash

exec php -q /path/to/php/script.php

This is where it fails. The PHP script is never executed, and the browser just keeps waiting for a response, until it results in a 500 error after a couple of minutes.

The PHP script it's trying to run is just one line:

#!/usr/bin/php -q

<?php

    file_put_contents('/path/to/folder/output.txt', 'some text');

?>

A few things worth noting:

  • The Bash script runs the PHP code if I run it through the CLI.
  • Everything works just fine on the local server, installed through XAMPP on OS X
  • The problem is on the remote server. CentOS with WHM/cPanel installed.
  • The files mentioned above have 777 permissions.
  • I can't get any clues from the return values in the exec() function because the script ends with a 500 error after 'hanging' for a couple of minutes.

Any ideas?

8
  • 2
    is php in the path of the bash that's being invoked? have you try exec /absolute/path/to/php -q ...? Commented Mar 21, 2014 at 13:46
  • 2
    Why on earth are you using PHP to call a bash script which runs a PHP script?? Commented Mar 21, 2014 at 13:48
  • Why don't you just include the php script in the other php script? Save yourself a fork and two execs. Commented Mar 21, 2014 at 13:57
  • Possibly related: PHP exec() not working properly Commented Mar 21, 2014 at 13:58
  • I forgot to add that the Bash script does run the PHP if launched through the CLI. So that means the PHP variables are setup correctly. @DigitalChris I know it looks ridiculous, but it makes sense in the actual scenario. Commented Mar 21, 2014 at 14:09

1 Answer 1

0

Found the solution thanks to Marc B. The issue was the path to the PHP bin. Even though /usr/bin/php path exists and the php variable was set in the environment, I needed to change both to /usr/local/bin/php. This was the correct path that I found with the PHP_BINDIR constant.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.