在 php 中执行 gulp 会返回错误,但在 shell 中工作


Executing gulp in php returns error but works in shell

我在从php脚本执行gulp时遇到了一个奇怪的问题。测试:

browser: http://server.com/pull.php <- does not work
shell: php pull.php <- works
shell: gulp <- works

这是我的设置:

Ubuntu 12.04.5 LTS
Node v5.6.0
PHP 5.5.30-1+deb.sury.org~precise+1 (cli) (built: Oct  4 2015 16:14:34)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

以下是package.json中的软件包:

"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-less": "^3.0.5",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.5.2",
"gulp-uglifycss": "^1.0.6",
"gulp-watch": "^4.3.5"

当我从 shell 运行它时,它运行得很好,但在 php 中作为网络服务器运行时返回错误:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Object #<Object> has no method 'existsSync'
    at /usr/local/lib/node_modules/gulp/node_modules/liftoff/lib/find_config.js:21:10
    at Liftoff.buildEnvironment (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:67:20)
    at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:192:32)
    at /usr/local/lib/node_modules/gulp/node_modules/liftoff/node_modules/flagged-respawn/index.js:17:3
    at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:185:9)
    at /usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:159:9
    at /usr/local/lib/node_modules/gulp/node_modules/v8flags/index.js:99:14
    at Array.0 (/usr/local/lib/node_modules/gulp/node_modules/v8flags/index.js:38:7)
    at EventEmitter._tickCallback (node.js:192:41)

运行它的命令很简单:passthru('gulp 2>&1'); 。我不知道出了什么问题,文件的所有者,Web服务器(nginx运行方式)用户和git所有者是名为git的同一用户。尝试了各种不同的事情,如制作bash脚本以从php运行它,但没有运气。我猜我缺少一些系统变量?

提前感谢,如果您需要更多信息,请告诉我。

事实证明,

节点不能很好地与gulp一起玩。我的解决方案:

passthru('node ./node_modules/gulp/bin/gulp.js 2>&1');

我无法解释为什么,只是尝试了几个随机的想法,那个想法奏效了。不过有一件事困扰着我,为什么我无法获得有关git pull的完整信息?我只得到:

Updating dcd958f..db05960
相关文章: