0

I am trying to run PhantomJS from a PHP script using exec('/path/to/phantomjs/phantonjs --version'); This line works fine from the CLI but does not work at all from my PHP script.

I have searched around for a fix and found this Q/A and read something about permissions that can be the problem. I have try all these fixes and still, PhantomJS does not launch.

I'm desperate at this point, can someone help me out? Thanks.

Community
  • 1
  • 1
  • Are you expecting that to output something? You need to `echo` the returned value. – pguardiario Dec 01 '16 at 01:43
  • I have echoed it and even tried adding an output array as second parameter for exec but the command simply does not run. :( – Eddy Ntambwe Dec 01 '16 at 09:14
  • Can you create a minimum version of your script that doesn't work, and post that? Have you been able to get `exec` to work using the interactive interpreter using `php -a`? – daphtdazz Dec 01 '16 at 09:42
  • I have PhantomJS in `/usr/local/bin`. The binary is executable and I have both permissions and ownership. I use a script as simple as `$cmd = '/usr/local/bin/phantomjs --version';` This obviously works flawlessly from the CLI but when called from PHP with: `$response = exec($cmd, $out, $status) ;` The status returns `true` meaning the command was not executed and both `$response` and `$out` are empty. Not `null` but respectively an empty string and an array of strings with one empty string element. – Eddy Ntambwe Dec 01 '16 at 10:51
  • Maybe something in php.ini is preventing it. – pguardiario Dec 01 '16 at 22:41

2 Answers2

1

Your path looks wrong in the exec command, it uses phantonjs where I'd expect it to be phantomjs. Might that be the problem?

daphtdazz
  • 7,754
  • 34
  • 54
0

I solved it. PhantomJS required som libraries that were not found in my Xampp packages and was just failing silently and updating the logs. So I just install the standalone PHP and Apache services and everything worked fine.