Node PhantomJs throwing errors for 75+ concurrent requests ,这里的请求数量有点无关紧要。这只是问题在这一点上暴露出来。我怀疑要么请求超时,要么底层套接字不能与 nodeJs 很好地配合。我正在尝试查明问题,并且肯定会感谢任何帮助。
错误日志:
phantom stdout: :67 in onclose
phantom stdout: [WDS] Disconnected!
phantom stdout: :67 in onclose
phantom stdout: TypeError: undefined is not an object (evaluating 'parent._jp.anxzqzn')
http://localhost:9000/sockjs-node/592/4vgdvqkc/htmlfile?c=_jp.anxzqzn:8 in global code
TypeError: undefined is not an object (evaluating 'c.message')
http://localhost:9000/sockjs-node/592/4vgdvqkc/htmlfile?c=_jp.anxzqzn:10 in p
phantom stdout: TypeError: undefined is not an object (evaluating 'c.message')
http://localhost:9000/sockjs-node/592/4vgdvqkc/htmlfile?c=_jp.anxzqzn:10 in p
TypeError: undefined is not an object (evaluating 'c.message')
http://localhost:9000/sockjs-node/592/4vgdvqkc/htmlfile?c=_jp.anxzqzn:10 in p
节点服务器:^0.10.40 5.3.0 稳定
尝试使用两个节点版本进行验证;这不是 NodeJ 的问题
代码片段:
page.open(decodedURL, function (status) {
if (status !== "success") {
console.log("phantom app failed to respond");
response.statusCode = 400;
response.write('Unable to load url: ' + decodedURL);
response.end();
//Close page object as we're returning response
console.log("closing objects");
ph.exit()
//phantom.exit
} else {
//Wait for all callback from the phantom app before rendering
console.log("Waiting for callback");
page.set('onCallback', function () {
//console.log("Callback name"+this.name);
console.log("received callback from app so rendering now");
renderImages();
/*else {
responseImages.push(page.renderBase64());
ph.exit()
}
*/
});
// Otherwise wait for maxTimeout, unless invoked earlier by callback from app
//If we reach the max timeout we throw an error and just return
//This is because we don't want to return half loaded images back to the caller
//garbage collect page as well
var forceRenderTimeout = setTimeout(function () {
console.log("Reached the maximum timeout so returning 400");
response.statusCode = 400;
response.write('Unable to load url: ' + decodedURL);
response.end()
console.log("closing objects");
ph.exit()
//phantom.exit
// page.close();
}, defaultOpts.maxTimeout);
}
});
PhantomJs:github.com/ariya/phantomjs PhantomJs_Node:github.com/sgentle/phantomjs-node
当前代码中使用的回调机制:phantomjs.org/api/webpage/handler/on-callback.html