在Heroku上运行Phantomjs +节点时遇到问题

Mat*_* E. 13 heroku node.js phantomjs

我已成功让Phantomjs在Heroku上工作,但现在我遇到了node.js的phantomjs-node接口问题(请参阅https://github.com/sgentle/phantomjs-node).

当我试图初始化Phantom时,我看到了10-15秒的延迟,然后:

> phantom stdout: ReferenceError: Can't find variable: socket

phantom stdout:   phantomjs://webpage.evaluate():1
  phantomjs://webpage.evaluate():1
  phantomjs://webpage.evaluate():1
Run Code Online (Sandbox Code Playgroud)

您可以通过以下步骤重现问题,或者通过https://github.com/matellis/phantom-test下载我的测试应用程序

git init phantom-test
cd phantom-test
heroku apps:create
# create node app as per Heroku instructions here https://devcenter.heroku.com/articles/nodejs
# copy bin and lib folders from http://phantomjs.googlecode.com/files/phantomjs-1.6.1-linux-x86_64-dynamic.tar.bz2 into root of your new project
# if you don't do this step you'll get an error "phantom stderr: execvp(): No such file or directory"
git add .
git commit -m "init"
git push heroku
Run Code Online (Sandbox Code Playgroud)

测试你的应用程序已经出现,第三行到最后一行会告诉你URL,它应该是这样的:

http://fathomless-ravine-5563.herokuapp.com deployed to Heroku
Run Code Online (Sandbox Code Playgroud)

如果成功,你应该看到Hello World!在您的浏览器中.

现在,从与Heroku应用程序相同的文件夹运行:

heroku run node
Run Code Online (Sandbox Code Playgroud)

在节点提示符处尝试以下操作:

phantom = require('phantom');
x = phantom.create();
Run Code Online (Sandbox Code Playgroud)

等待10-15秒,你应该看到错误.从这一点来看,没有任何作用.

这应该输出文件foo.png:

x = phantom.create(function(ph){ph.createPage(function(page){ page.open('http://bbcnews.com', function(status){ page.render('foo.png', function(result) {ph.exit()}); }); }); });
Run Code Online (Sandbox Code Playgroud)

要验证Phantomjs在Heroku上正常工作,请使用我的测试项目尝试以下方法:

>heroku run bash
Running `bash` attached to terminal... up, run.1
~ $ phantomjs test.js http://bbcnews.com foo.png
~ $ ls *.png
foo.png
Run Code Online (Sandbox Code Playgroud)

我无法在本地重现任何这些问题,但还有其他问题报告,人们可能在本地遇到此问题.

问题似乎源于shim.js1637行:

s.on('request', function(req) {
  var evil;
  evil = "function(){socket.emit('message', " + (JSON.stringify(JSON.stringify(req))) + " + '\\n');}";
  return controlPage.evaluate(evil);
});
Run Code Online (Sandbox Code Playgroud)

我尝试了各种版本的节点,幻像等,没有运气.

我也尝试过设置DYLD变量的自定义buildpack,请参阅http://github.com/tecnh/heroku-buildpack-nodejs也没有运气.

任何让Phantom + Node在Heroku上很好地一起玩的人请告诉我.在Stackoverflow上有几个引用,但没有人说"我得到它工作,这是如何".

asg*_*oth 0

Heroku 不支持 WebSocket。Socket.io 有一个解决方法。不确定dnode, 的phantomjs-node用途。

我在 Heroku 上的 WebSockets 也遇到了问题,我切换到Nodejitsu,它为我解决了这个问题。