首页 > 解决方案 > PhantomJS PHP exec()命令在浏览器中不起作用

问题描述

我正在使用 phantom 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() 但没有成功。 在此处输入图像描述

hpantomjs 的权限是 read 和 write :在此处输入图像描述

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

标签: phppermissionsphantomjs

解决方案


推荐阅读