0

我已经安装了CasperJS,没有问题,并且正确配置了脚本&当我直接通过命令行执行时 - 我现在希望让我的PHP Codeigniter应用程序'talk-到'这个脚本,并能够通过我的web应用程序执行相同的脚本。我正在运行XAMPP - 尽管最终产品将部署在LAMP服务器上。通过PHP运行命令行(带CasperJS)

要通过我用CMD运行脚本(successfuly如下:)

casperjs test.js 

我已经创建了一个基本的控制器内笨。下面这行,但好像没有什么改变?任何人都可以建议我做错了什么?

public function run() 
{ 
    shell_exec('casperjs test.js'); 
} 
+0

为什么不尝试使用卡斯帕作为服务,而不是通过命令行运行它?请参阅http://stackoverflow.com/questions/15852987/casperjs-passing-data-back-to-php/16489950#16489950 –

回答

1

我只允许通过命令行运行控制器的方式是检查它是否是命令行请求。我在控制器文件中验证了这一点。

if (!$this->input->is_cli_request()){ 
     //redirect them to the homepage 
     redirect('', 'refresh'); 
    }else{ //Request is coming from the command line } 

若要从Linux服务器上的命令行控制器使用这样的命令:

/usr/bin/php /var/www/website/index.php controller_name function_name 

请参阅此链接了解更多信息:http://ellislab.com/codeigniter/user-guide/general/cli.html