节点PhantomJs为75个以上的并发请求抛出错误,请求数量在这里有点无关紧要。此时只暴露了问题。 我怀疑任何一个请求都是超时或底层套接字与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稳定
尝试使用两个节点版本进行验证;它不是NodeJs问题
代码段:
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