脚本宝典收集整理的这篇文章主要介绍了如何解决错误QXcbConnection:使用PHP的phantomJs使用exec函数时无法连接显示,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
导游:/VAR/www/htML/phantom/index.js
var page = require('webpage').create(); var fs = require('fs'); page.oPEn('http://insttaorder.COM/',function(status) { // Get all links to CSS and JS on the page var links = page.evaluate(function() { var urls = []; $("[rel=stylesheet]").each(function(i,css) { urls.push(css.href); }); $("script").each(function(i,js) { if (js.src) { urls.push(js.src); } }); return urls; }); // Save all links to a file var url_file = "list.txt"; fs.wrITe(url_file,links.join("\n"),'w'); // Launch wget PRogram to download all files From the list.txt to current // folder require("child_process").exeCFile("wget",[ "-i",url_file ],null,function(err,stdout,stderr) { console.LOG("execFileSTDOUT:",stdout); console.log("execFileSTDERR:",stderr); // After wget finished exit PhantomJS phantom.exit(); }); });
导游:/var/www/html/phantom/index.PHP
exec('/usr/bin/phantomjs index.js 2>&1',$output); echo '<pre>'; print_r($output); die;
也尝试过
exec('/usr/bin/phantomjs /var/www/html/phantom/index.js 2>&1',$output); echo '<pre>'; print_r($output); die;
运行后,我得到低于错误
Array ( [0] => QXcbConnection: Could not connect to display [1] => PhantomJS has crashed. Please read the bug reporting guide at [2] => and file a bug report. [3] => Aborted (core dumped) )
user2@user2-H81M-s:/var/www/html/phantom$PHP index.PHP
一个.将变量QT_QPA_PLATFORM定义或设置为屏幕外:
QT_QPA_PLATFORM=offscreen /usr/bin/phantomjs index.js
export QT_QPA_PLATFORM=offscreen
C.或安装包xvfb并在Phantomjs之前调用xvfb-run:
xvfb-run /usr/bin/phantomjs index.js
d.或使用参数平台:
/usr/bin/phantomjs -platform offscreen index.js
也许您不希望/不能在您的服务器上进行修改,在这种情况下,您可能会尝试从official website下载静态二进制文件:
/path/to/the/bin/folder/phantomjs index.js
和/或在.bash_aliases文件中创建一个别名,如下所示:
alias phantomjs=/path/to/the/bin/folder/phantomjs
一些参考:
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=817277
> https://github.com/ariya/phantomjs/issues/14376
> https://bugs.launchpad.net/ubuntu/+source/phantomjs/+bug/1586134
以上是脚本宝典为你收集整理的如何解决错误QXcbConnection:使用PHP的phantomJs使用exec函数时无法连接显示全部内容,希望文章能够帮你解决如何解决错误QXcbConnection:使用PHP的phantomJs使用exec函数时无法连接显示所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。