【问题标题】:Run command line through PHP (w/CasperJS)通过 PHP (w/CasperJS) 运行命令行
【发布时间】:2013-08-01 13:19:25
【问题描述】:

我已经毫无问题地设置了 CasperJS,并且当我直接通过命令行执行时,脚本已正确配置和工作 - 我现在希望我的 PHP Codeigniter 应用程序与此脚本“对话”并能够执行通过我的 Web 应用程序执行相同的脚本。我正在运行 XAMPP - 尽管最终产品将部署在 LAMP 服务器上。

要运行脚本(通过 cmd 成功,我使用以下命令:)

casperjs test.js

我在 Codeigniter 中使用以下行创建了一个基本控制器,但似乎没有任何反应?谁能建议我做错了什么?

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

【问题讨论】:

标签: codeigniter command-line phantomjs casperjs headless-browser


【解决方案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

【讨论】:

    猜你喜欢
    • 2011-11-10
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    相关资源
    最近更新 更多