本文介绍了无法将CasperJS结果传递回PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将CasperJS结果传递给PHP,但是它不起作用(输出为空).

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

这是我的代码:

<?php

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

print_r($array);

?>

exec适用于任何其他命令("echo hello"),但不适用于casperjs. $ array为空,执行时间是瞬时的...

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

PHP脚本当然与test.js在同一目录中

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

我猜这是一个路径问题,但是没有任何效果……我尝试了"/usr/local/bin/casperjs test.js",它返回了

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

有什么想法吗?

推荐答案

要解决此问题,我必须在PHP文件的开头添加以下两行:

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");

现在它可以工作了!

这篇关于无法将CasperJS结果传递回PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:19
查看更多