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?
exec /absolute/path/to/php -q ...?includethe php script in the other php script? Save yourself aforkand twoexecs.