php shell_exec and hg pull

时间:2015-07-28 17:05:02

标签: php mercurial shell-exec

I have written simple php script to help me update site contents when the commit is sent to bitbucket. I have following problem with it.

<?php
$repo_dir = '/var/www/vhosts/my_full_path';

$output = shell_exec('cd '.$repo_dir.' && hg --config auth.rc.prefix=https://bitbucket.org/XXXXX --config auth.rc.username=my_username --config auth.rc.password=my_pass pull -u https://bitbucket.org/XXXXXXX &');

echo $output;
?>

When I type it to web browser it doesn't work. The output of script is:

pulling from https://bitbucket.org/XXXXXXXXXXXXXX

but when I try to execute it under console on the server it works like a charm:

php myscript.php

generates following output:

pulling from https://bitbucket.org/XXXX
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 1 files
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

See the oupt is full and correct! in concole I'm using root user in web browser data-www? Is there any difference in this case?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。我希望它有所帮助。

有两个问题:

  • 我的回购目录的权限
  • 对此repo的用户www-data进行身份验证

发生此问题是因为Web浏览器在执行命令shell_exec时不会刷新警告并中止消息。如果要测试脚本,则必须通过SSH(例如root)进入控制台,然后以apache用户身份执行脚本/命令:

sudo -u www-data php /path-to-your-script/script.php

在控制台中,您将看到用户生成的所有问题。