First of all, I have installed phantomjs
.
the code of test.js
is:
var casper = require('casper').create();
if(casper.cli.has(0)){
var id = casper.cli.get(0);
casper.start("http://test.com/index.php?a=screenshot&id="+id, function() {
this.captureSelector(id+'.png', '.content');
});
casper.run();
}else{
casper.exit();
}
and when I run this
/usr/local/bin/casperjs test.js 124
on the command line is Ok, and there is an image(124.png) generated in the directory.
But when I use the php to excute the command ,there is an error.
My PHP code:
$id = 124;
$handle = popen('/usr/local/bin/phantomjs --version 2>&1','r');
$read = stream_get_contents($handle);
echo $read;//1.9.7
pclose($handle);
$handle = popen('/usr/local/bin/casperjs screenshot.js '.$id.' 2>&1','r');
$read = stream_get_contents($handle);
echo $read;//Fatal: [Errno 2] No such file or directory; did you install phantomjs?
pclose($handle);
when I access the php script througth the browser,the page output 1.9.7 Fatal: [Errno 2] No such file or directory; did you install phantomjs?