This just worked for me:
<?php
$cmd = "/usr/bin/php /home/auser/a.php &> /dev/null &";
exec($cmd,$output,$return);
sleep(30);
if($return===0)
{
echo 'Successful';
}
else
{
echo 'Unsuccessful';
}
?>
I saved it as runa.php and ran it from the command window as php runa.php.
It produced 3 files.
running a.php also worked from the cron job:
]$ crontab -l
18 * * * * /usr/bin/php /home/auser/a.php
I put the script in a web directory and find that I have some writing problems. What can you see in the server log?
sudo tail -f /var/log/httpd/error_log
And what if you hit a.php from the web browser? Because you mention the script is 755, but how about the directory. Maybe it needs to be 775 or 777 for testing so that the script can write a file?
For testing I created a sub directory "output" and changed a.php
<?php
ini_set('date.timezone','America/New_York'); //without this it makes extra messages
error_log("a.php putting contents", 0);
file_put_contents("output/".date("s"),"");
sleep(5);
file_put_contents("output/".date("s"),"");
sleep(5);
file_put_contents("output/".date("s"),"");
error_log("a.php done", 0);
?>
It was unable to write files until I gave write permission to the ouput folder
sudo chmod 777 /var/www/html/output
Then I found out the apache user is writing the files:
~]$ sudo ls -l /var/www/html/output/
total 0
-rw-r--r--. 1 apache apache 0 Apr 18 11:38 00
-rw-r--r--. 1 apache apache 0 Apr 18 11:38 05
-rw-r--r--. 1 apache apache 0 Apr 18 11:37 55
So I changed the owner of output, in order to tone down the permissiosn again.
~]$ sudo ls -lu /var/www/html/ | grep output
drwxr-xr-x. 2 apache root 4096 Apr 18 12:21 output
This also works now:
~]$ sudo ls -l /var/www/html/output
total 0
-rw-r--r--. 1 apache apache 0 Apr 18 12:21 44
-rw-r--r--. 1 apache apache 0 Apr 18 12:21 49
-rw-r--r--. 1 apache apache 0 Apr 18 11:37 55