node-phantom createPage()从不调用回调 [英] node-phantom createPage() never calls callback

查看:106
本文介绍了node-phantom createPage()从不调用回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将nodejs与node-phantom模块一起使用了一段时间。它工作正常。
现在我在另一台机器上尝试它并且相同的代码示例不起作用:

I used nodejs with node-phantom module for some time. It worked fine. Now I try it on another machine and same code example don't work:

var Scan=function(request,response)
{
    var parsedURL=url.parse(request.url,true);
    if(parsedURL.query.site)
    {
        console.log("scanning "+parsedURL.query.site);
        phantom.create(function(err,ph) {
            console.log(err);
            return ph.createPage(function(err,page) {
                console.log(err);
                return page.open(parsedURL.query.site, function(err,status) {
                    console.log("opened site? ", status);
                    if (status=="fail") {
                        response.writeHead(404, {'Content-Type': 'text/plain'});
                        response.end('URL not found');
                        return;
                    }
                    var filename="temp.jpg';
                    console.log(filename);
                    page.render(filename,function(err){
                        if (err) {
                            console.log(err);
                            return;
                        }

                        page.close(function(){
                            response.writeHead(404, {'Content-Type': 'text/plain'});
                            response.end('URL not found');
                        });
                    });
                   console.log("opened site? ", status);
                if (status=="fail") {
                    response.writeHead(404, {'Content-Type': 'text/plain'});
                    response.end('URL not found');
                    return;
                }
                var filename="temp.jpg';
                console.log(filename);
                page.render(filename,function(err){
                    if (err) {
                        console.log(err);
                        return;
                    }

                    page.close(function(){
                        response.writeHead(404, {'Content-Type': 'text/plain'});
                        response.end('URL not found');
                    });
                });
             });
           });
        });
    }
}

它永远不会进入createPage()回调,看起来像nodejs和phantomjs之间缺乏通信。
nodejs版本:0.10.10
phantomjs版本:1.9.1

It never gets inside createPage() callback and it looks like lack of communication between nodejs and phantomjs. nodejs version: 0.10.10 phantomjs version: 1.9.1

我如何检查它有什么问题?

How can I check what wrong with it?

UPD:安装新的Debian发行版,现在它有时会在控制台中抛出以下警告。

UPD: Installed new Debian distro and now it throws folowing warning in the console sometimes.


警告 - 客户端没有握手客户端应该重新连接

warn - client not handshaken client should reconnect

看起来像socket.io问题。

It looks like socket.io problem.

推荐答案

很难准确诊断但是我尝试使用以下针对不匹配引用的修复程序的代码,它似乎在v0.10.6上正常工作。这两行看起来像:

Well hard to diagnose exactly but I tried your code with the following fixes for the mismatched quotations and it seems to work fine on v0.10.6. These 2 lines that look like:

var filename="temp.jpg';

需要先修复。

我最好的猜测是你有一个32位而不是64位有点问题...当你切换机器时看到它失败或工作。所以我通过在64位系统上安装32位节点来模拟,以显示这类事情的故障排除程序:

My best guess is that you have a 32 bit versus 64 bit problem... seeing as you switch machines and it fails or works. So I simulated that by installing 32 bit node on a 64 bit system to show the troubleshooting procedure for that sort of thing:

首先检查退出代码:

[node@hip1 blah]$ phantomjs
[node@hip1 blah]$ $?
-bash: 127: command not found

全部关注符号链接并直接运行可执行文件,例如在我的系统上:

follow all the symlinks and run the executable directly, for example on my system:

[node@hip1 blah]$ which phantomjs
~/node/bin/phantomjs
[node@hip1 blah]$ ls -l ~/node/bin/phantomjs
lrwxrwxrwx. 1 node node 43 Jun 16 20:06 /node/node/bin/phantomjs -> ../lib/node_modules/phantomjs/bin/phantomjs
[node@hip1 blah]$ ls -l /node/node/lib/node_modules/phantomjs/bin/phantomjs
-rwxr-xr-x. 1 node node 540 Jun 16 20:14 /node/node/lib/node_modules/phantomjs/bin/phantomjs

执行...

[node@hip1 blah]$ /node/node/lib/node_modules/phantomjs/bin/phantomjs
/node/libs/node-v0.10.6-linux-x86/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory

啊,请注意该库末尾的.6,这是一个64位系统,但我们安装了32位节点以避免内存问题,并且还注意到它具有更好的性能。所以npm安装phantomjs去了32位版本。所以现在我需要这些库的devel i686版本,如果我没有指定则不会安装 - 而是我会得到x86_64版本。所以做其中的一些:

Ah, notice the .6 on the end of that library, it's that this is a 64 bit system but we have installed 32 bit node to avoid memory issues and have also noticed better performance with it. So an npm install phantomjs goes and gets the 32 bit version of that. So now I'd need the devel i686 versions of those libraries, which won't be installed if I don't specify - instead I'll get the x86_64 versions. So do a few of these:

yum install freetype-devel.i686 或debian使用 apt-get install 。您可能还需要libfontconfig.so.1,它位于fontconfig-devel.i686中。

yum install freetype-devel.i686 or on debian use apt-get install. You might also need libfontconfig.so.1, which is in fontconfig-devel.i686.

最后!

phantomjs>

phantomjs>

之后事情可能会奏效。

这篇关于node-phantom createPage()从不调用回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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