1

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.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
E.S.
  • 511
  • 1
  • 4
  • 6
  • Why `PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs php /path/to/file/test.php`? Have you tried with `PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs`? – Artjom B. Aug 27 '15 at 15:33
  • I tried with and without the PHANTOMJS_EXECUTABLE. Some have suggested that this might be a solution, but it did not help... – E.S. Aug 27 '15 at 15:36
  • I don't mean without. You simply have a wrong executable definition. `/usr/local/bin/phantomjs php /path/to/file/test.php` is not PhantomJS, but rather some kind of php file. – Artjom B. Aug 27 '15 at 15:37
  • Ah :-) The file that I call is a PHP file, as that PHP file contains a shell_exec to the casperjs script. so, the base cronjob would be php /path/to/file/test.php – E.S. Aug 27 '15 at 15:39
  • My guess is that you should pass absolute path to your `test.js` – Jonatas Walker Sep 01 '15 at 09:47
  • Sadly, I tried that also, but it did not work. I also tried running under root account the cronjob, but no solution yet... – E.S. Sep 03 '15 at 17:02

1 Answers1

0

I have seen the same error, because my machine has installed some versions of python. So you should install python 2.6+ or edit /usr/local/bin/casperjs. Thanks

from

OSError as err:

to

OSError, err:

Python try...except comma vs 'as' in except

Community
  • 1
  • 1
smapira
  • 87
  • 7