PhantomJS PHP exec()命令无法在浏览器

时间:2018-05-27 16:00:54

标签: php permissions phantomjs

我使用幻像JS来获取网页的原始HTML。 当我使用终端但不在浏览器中时,它正在工作。 请参考照片:

exec("/Users/kaustubh/Desktop/phantomjs /Users/kaustubh/Desktop/loadspeed.js "."http://www.google.com ",$output);
var_dump($output);

我已经提到了许多类似的问题,结论是与许可有关。

您如何看待此错误? loadspeed.js 的代码是:

var page = require('webpage').create(),system = require('system'),t, address;
 if (system.args.length === 1) {
console.log('Usage: loadspeed.js <some URL>');
phantom.exit(1);
}else{
address=system.args[1];
var websiteAddress = address;
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 
Safari/537.36';
page.viewportSize = { width: 1920, height: 1080 };

 page.clipRect = { top: 0, left: 0, width: 1920, height: 1080 }; page.open(websiteAddress, function (status) {
    setTimeout(function(){
    page.render('github.png');
    console.log(returnChunksArray(page.content,6000));
    phantom.exit();
 }, 5000); // 5 sec should be enough
});
}
function returnChunksArray(str, chunkSize) {
 var arr = [];
 while(str !== '') {
    arr.push(str.slice(0, chunkSize));
    str = str.slice(chunkSize);
 }
 return arr;
}

当涉及浏览器时:浏览器甚至不等待 exec()功能。我甚至尝试过shell_exec()但没有成功。 enter image description here

hpantomjs的权限是读写:enter image description here

但是在终端中,它按预期加载。 感谢

0 个答案:

没有答案