Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 节点幻影createPage()从不调用回调_Javascript_Node.js_Phantomjs - Fatal编程技术网

Javascript 节点幻影createPage()从不调用回调

Javascript 节点幻影createPage()从不调用回调,javascript,node.js,phantomjs,Javascript,Node.js,Phantomjs,我使用nodejs和node-phantom模块有一段时间了。它工作得很好。 现在我在另一台机器上尝试,但相同的代码示例不起作用: var Scan=function(request,response) { var parsedURL=url.parse(request.url,true); if(parsedURL.query.site) { console.log("scanning "+parsedURL.query.site); p

我使用nodejs和node-phantom模块有一段时间了。它工作得很好。 现在我在另一台机器上尝试,但相同的代码示例不起作用:

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()回调,并且看起来NodeJ和phantomjs之间缺乏通信。 nodejs版本:0.10.10 phantomjs版本:1.9.1

我如何检查它有什么问题

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

警告-客户端未握手客户端应重新连接


这看起来像是socket.io问题。

很难准确诊断,但我尝试了您的代码,并对不匹配的引用进行了以下修复,并且似乎在v0.10.6上运行良好。这两行看起来像:

var filename="temp.jpg';
首先需要修理

我最好的猜测是你有一个32位对64位的问题。。。当你切换机器时,它会失效或工作。因此,我通过在64位系统上安装32位节点来模拟这一情况,以显示此类问题的故障排除过程:

首先检查退出代码:

[node@hip1 blah]$ phantomjs
[node@hip1 blah]$ $?
-bash: 127: command not found
遵循所有符号链接并直接运行可执行文件,例如在我的系统上:

[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位版本。因此,现在我需要这些库的develi686版本,如果我不指定,就不会安装这些库——相反,我将获得x86_64版本。下面是其中一些:

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

最后

幻影>

在那之后,事情可能会起作用