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');
});
});
});
});
});
}
}
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: Installed new Debian distro and now it throws folowing warning in the console sometimes.
warn - client not handshaken client should reconnect
It looks like socket.io problem.
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:
need fixing first.
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:
First check the exit code:
follow all the symlinks and run the executable directly, for example on my system:
execute that...
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
or on debian useapt-get install
. You might also need libfontconfig.so.1, which is in fontconfig-devel.i686.And finally!
phantomjs>
After that things should probably work.