【问题标题】:Running a 'git pull' from EXEC in PHP在 PHP 中从 EXEC 运行“git pull”
【发布时间】:2012-05-28 05:32:28
【问题描述】:

我正在尝试在运行 XAmpp 的 Windows 上使用 PHP 的 exec 从 git 运行拉取请求。当使用execsystem 运行下面的脚本并尝试访问文件时,页面永远不会停止加载。我检查了目录的文件权限,它们都是 0777。运行git status 运行良好。不知道是什么问题。

<?php
ignore_user_abort(true);
set_time_limit(15);
exec('git pull origin master', $o);
echo implode("\n", $o);
?>

更新帐户没有密码:

C:\xampp\htdocs>git pull origin master
From github.com:************
 * branch            master     -> FETCH_HEAD
Already up-to-date.

C:\xampp\htdocs>

从终端运行我得到:

C:\xampp\htdocs>php -f update.php
PHP Warning:  PHP Startup: ming: Unable to initialize module
Module compiled with build ID=API20090626,TS,VC6
PHP    compiled with build ID=API20090626,TS,VC9
These options need to match
 in Unknown on line 0

Warning: PHP Startup: ming: Unable to initialize module
Module compiled with build ID=API20090626,TS,VC6
PHP    compiled with build ID=API20090626,TS,VC9
These options need to match
 in Unknown on line 0
From github.com:*********
 * branch            master     -> FETCH_HEAD
Already up-to-date.
C:\xampp\htdocs>

【问题讨论】:

  • git 是否在等待其他用户输入,例如密码? set_time_limit() 在这里没有帮助,因为它只适用于 PHP 执行时间。
  • 没有密码也更新了帖子。
  • 您正在从终端运行 PHP 脚本,是吗?或者,您是从网络上运行它吗?如果来自网络,我敢打赌你的 git 配置取决于你的环境变量,如果从不同的用户(网络服务器的用户)运行,环境变量会有所不同。
  • 从您的终端运行它。看看它是否在那里工作。
  • 更新了帖子。我不确定这 2 个警告是什么,但它确实会在几秒钟内运行并完成。

标签: php windows git xampp exec


【解决方案1】:

不要使用exec,它会等到进程完成,而是使用passthru,并确保您禁用了输出缓冲。这样您就可以立即看到问题所在。

【讨论】:

    猜你喜欢
    • 2012-03-11
    • 2011-12-28
    • 2014-08-16
    • 2011-10-23
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    相关资源
    最近更新 更多