Cannot pass CasperJS result back to PHP

我们两清 提交于 2019-12-13 04:20:03

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/25001258/cannot-pass-casperjs-result-back-to-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!