Why i'm unable to execute
phantomjs
form exec
in laravel 5.4
the step i have followed
downloaded
phantomjs
from http://phantomjs.org/ and placed inside root ofproject
(laravel root)placed script inside
public/js/phantom.js
i did something like this in laravel
Route::get('phantomjs',function(){
$basePath = base_path();
$jsPath = $basePath.'\\public\\phantom.js';
$phantom = $basePath.'\\phantomjs.exe';
$response = exec("$phantom $jsPath https://stackoverflow.com/questions/20202407/how-to-execute-phantomjs-from-php stack.pdf");
dd($response);
});
here is my phantom.js script
var page = require( 'webpage' ).create(),
system = require('system');
/**
* Check for required parameters
*/
if ( system.args.length < 3 ) {
console.log( 'Usage: report.js <some URL> <output path/filename>' );
phantom.exit();
}
/**
* Grab the page and output it to specified target
*/
page.open( system.args[ 1 ], function( status ) {
window.setTimeout(function () {
console.log( "Status: " + status );
if ( status === "success" ) {
//page.render( 'example22.pdf');
page.render( system.args[ 2 ] );
}
phantom.exit();
}, 12000);
} );
Here is my project (you can downoload):
https://www.dropbox.com/s/1abkqlzyqg1u6ae/phantom.zip?dl=0
(after download) please visit this url =>
localhost:8000/phantomjs
Thanks in Advance!!