2

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).

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • 2
    I would suggest trying to use http://us3.php.net/manual/en/function.popen.php in lieu of exec and see if you can read an actual error being output. – sberry Sep 13 '11 at 17:59
  • @sberry2A: Dude! Thanks a lot! ` Fatal error: Error in creating unison directory /.unison: Permission denied [mkdir(/.unison)]`. Think I can fix that! – gen_Eric Sep 13 '11 at 18:24

1 Answers1

1

I fixed it! Using popen (thanks @sberry2A) I saw an error.

Fatal error: Error in creating unison directory /.unison: Permission denied [mkdir(/.unison)]

I ran chdir('/home/user');, before running the command, and then saw an error about HOME not being set.

So, I added HOME=/home/user before the command. Now it works, and I don't need the chdir command either!

exec("HOME=/home/user /usr/bin/unison /var/www/html/files ssh://a2//var/www/html/files -batch -prefer newer -times -path uploads", $out, $r);
gen_Eric
  • 223,194
  • 41
  • 299
  • 337