As a test, I have the following PHP sript:
<?php
print shell_exec("/usr/local/bin/casperjs test.js --ssl-protocol=any --verbose");
?>
The casperjs script is the following:
var casper = require('casper').create();
casper.start('http://casperjs.org/', function() {
this.echo(this.getTitle());
});
casper.thenOpen('http://phantomjs.org', function() {
this.echo(this.getTitle());
});
casper.run();
I would expect an output like:
CasperJS, a navigation scripting and testing utility for PhantomJS and SlimerJS PhantomJS | PhantomJS
This actually works fine in commandline. However, I need to run a PHP script that calls a CasperJS script in a Cronjob.
PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs php /path/to/file/test.php
Somehow, when I do that, I get the following error:
File "/usr/local/bin/casperjs", line 138
except OSError as err:
^
SyntaxError: invalid syntax
X-Powered-By: PHP/5.4.21
Content-type: text/html
I have tried to set the environment variable for PhantomJS, but it does not help. I stripped down my own script to the above to ensure that this error has nothing to do with my own coding.
Anybody any idea how to get CasperJS working in a PHP script from a Cronjob?
BTW: I use CentOS.