Question

I have setup CasperJS without a problem and have a script correctly configured & working when I execute directly via the command line - I would now like to have my PHP Codeigniter application 'talk-to' this script and be able to execute the same script via my web application. I am running XAMPP - although the final product will be deployed on a LAMP server.

To run the script (successfuly via the cmd I use the following:)

casperjs test.js

I have created a basic controller within Codeigniter with the following line but nothing seems to happen? Can anyone suggest what I am doing wrong?

public function run()
{
    shell_exec('casperjs test.js');
}
Was it helpful?

Solution

The way I only allow a controller to be run by the command line is to check if it is a command line request. I validate this in the controller file.

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

To run a controller from a command line on a linux server use a command like this:

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

See this link for more information: http://ellislab.com/codeigniter/user-guide/general/cli.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top