1
votes

I'm running PHP 5.4.9 on Windows server

I've tried running all script commands in PHP (exec, shell_exec, system, proc_open, passthru). All seem to return empty or null.

I've added phantomjs as a PATH variable.

And running phantomjs --version in command prompt, and it returns 1.8.2

Although when I try to run

$return = exec("phantomjs --version")

or

$return = shell_exec("phantomjs --version", $output)

$return is always null and $output is empty.

I made sure IUSR and IIS_IUSRS users have permission to run phantomjs.exe

Safe mode is disabled in php.ini

Also, I tried running exec('ls') && exec('ipconfig /all'), and those output the data I'm expecting.

I'm not sure what else to try.

2
are you sure phantomjs is in the path of the shell being exec()'d by the server? just because it's in YOUR account's path, it may not be in the IUSR_IIS account's path. - Marc B
Try the following and see if either $out or $ret are populated. $out will be an array. exec('phantomjs --version'.' 2>&1',$out,$ret); - Gavin
The path is in the System Variables -> Path variable. - Mike Jouwstra
when using Gavin's recommendation, $out returns an empty array, and $ret is 1. exec('phantomjs --version'.'2>&1',$out,$ret); out: array(0) { } ret: int(1) - Mike Jouwstra
Not especially helpful, but I can tell you that 1 is an error code (should be 0) and $out should have caught any output to standard out, so looks like there was none. If you have control over the server try setting the php process to run under a system account (for testing only) to clear the doubt of permissions issues. - Gavin

2 Answers

1
votes

I was facing the same problem.. The thing is phantomjs requires complete path for all Here is the solution I came up with:

$getout = exec('D:\\xampp\\htdocs\\phantomjsdir\\phantomjs.exe D:\\xampp\\htdocs\\rasterisejsdir\\rasterize.js http://localhost/pagetobecaptured/test D:\\xampp\\htdocs\\outputfiledir\\test2.jpg "1800px*840px"',$o,$e);
0
votes

You are pretty close to a solution. It's basically:

$stdout = shell_exec('time /T');
echo $stdout;

You need to make sure, that the Phantom binary is either on path or called with full-path.

For a full example executing PhantomJS, see the driver file of "jakoch/PHPUnit-headless".