尝试在Rails应用程序中捕获屏幕捕获页面时,PhantomJS.rb冻结 [英] PhantomJS.rb freezing when trying to screen capture page in my rails application

查看:72
本文介绍了尝试在Rails应用程序中捕获屏幕捕获页面时,PhantomJS.rb冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 phantomjs.rb 时,我无法从应用程序中获取屏幕截图.宝石.我目前正在尝试使用本地网址.如果我能正常工作,我将在以后使用url_for.

I'm having trouble getting a screen capture from my application while using the phantomjs.rb gem. I'm currently just trying local url's. If I get those working I'll use url_for's later.

在我的控制器中:

Phantomjs.run('./public/javascripts/testScreenCapture.js', 'http://localhost:3000')

还有我的testScreenCapture.js:

And my testScreenCapture.js:

var page = require('webpage').create();

var args = require('system').args;
var url = args[1];

page.open(url, function () {
    window.setTimeout(function () {
      page.render('./public/appPage.png');
      phantom.exit();
    }, 3000);
});

通过" http://www.google.com 作为url参数可以正常工作,只是在当Rails服务器挂起时,我会从本地服务器传递任何信息,并且我也假设使用phantomjs脚本,因为我的公用文件夹中没有屏幕截图.

Passing "http://www.google.com" as the url argument works fine, it's just when I pass anything from my local server is when the rails server hangs and I'm assuming the phantomjs script as well since I'm not getting an screenshot in my public folder.

更奇怪的是从命令行运行它:

What's even more odd is running this from command line:

phantomjs public/javascripts/testScreenCapture.js http://localhost:3000

这很好用!所以我假设我的控制器与服务器冲突是有问题的.有什么想法吗?

This works great! So I'm assuming it's something wrong with my controller conflicting with the server. Any ideas?

推荐答案

您必须使用多线程Web服务器,例如

You have to use a multi-threaded web server like puma.

有关不同选项的概述,请参见此处.

See here for an overview of different options.

另一个陷阱可能是您的控制器逻辑.如果由幻像渲染的页面触发的控制器动作与调用幻像的页面相同,则您将创建无限循环.

Another pitfall might be your controller logic. If the page, that gets rendered by phantom, triggers the same controller action than the one, that calls phantom, you create an infinite loop.

然后,即使是多线程服务器也会卡住:)

Then, even a multi-threaded server would get stuck :)

这篇关于尝试在Rails应用程序中捕获屏幕捕获页面时,PhantomJS.rb冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆