Nelty
Nelty

Reputation: 119

Cannot pass CasperJS result back to PHP

I am trying to pass CasperJS results to PHP but it's not working (the output is empty).

Here is my code:

<?php

exec("casperjs test.js", $array);

print_r($array);

?>

The exec works for any other command ("echo hello"), but not casperjs. $array is empty and execution time is instantaneous...

The PHP script is of course in the same directory as test.js

I'm guessing it's a path issue but nothing works... I've tried "/usr/local/bin/casperjs test.js", it returns

Fatal: [Errno 2] No such file or directory; did you install phantomjs?

Any ideas?

Upvotes: 0

Views: 802

Answers (1)

Nelty
Nelty

Reputation: 119

To solve this issue, I had to add these two lines at the beginning of my PHP file:

putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
putenv("DYLD_LIBRARY_PATH");

And now it works!

Upvotes: 1

Related Questions