I’m using Unison to sync files between two servers. I’m trying to get PHP to call it after a file is uploaded.
I’m using exec, but it’s returning an error code of 2.
exec("/usr/bin/unison /var/www/html/files ssh://a2//var/www/html/files -batch -prefer newer -times -path uploads", $out, $r);
$out is a blank array, and $r is 2. What does an error code of 2 mean?
P.S. I ran php -a on the command line, and copied and pasted that line, and it worked. Also, exec('whoami') works (and is the same user I was logged in as on the command line).
I fixed it! Using
popen(thanks @sberry2A) I saw an error.I ran
chdir('/home/user');, before running the command, and then saw an error aboutHOMEnot being set.So, I added
HOME=/home/userbefore the command. Now it works, and I don’t need thechdircommand either!