简体   繁体   English

从PHP脚本调用时,CasperJS在Cron中不起作用

[英]CasperJS does not work in Cron when called from PHP script

As a test, I have the following PHP sript: 作为测试,我有以下PHP代码:

<?php
  print shell_exec("/usr/local/bin/casperjs test.js --ssl-protocol=any --verbose");
?>

The casperjs script is the following: casperjs脚本如下:

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. 但是,我需要运行一个PHP脚本,该脚本在Cronjob中调用CasperJS脚本。

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. 我试图为PhantomJS设置环境变量,但这无济于事。 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? 有人知道如何从Cronjob使CasperJS在PHP脚本中工作吗?

BTW: I use CentOS. 顺便说一句:我使用CentOS。

I have seen the same error, because my machine has installed some versions of python. 我看到了相同的错误,因为我的机器已经安装了某些版本的python。 So you should install python 2.6+ or edit /usr/local/bin/casperjs . 因此,您应该安装python 2.6+或编辑/usr/local/bin/casperjs Thanks 谢谢

from

OSError as err:

to

OSError, err:

Python try...except comma vs 'as' in except Python try ... except逗号与'as'除外

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 作为Cron的PHP脚本不起作用,但是来自CLI - PHP Script as Cron doesn't work, but does from CLI 使用 cron 运行 php-script 不起作用 - run php-script with cron does not work 我该如何解决为什么我的PHP脚本无法从命令行在cron中运行的问题? - How can I troubleshoot why my PHP script won't work in cron when it does from the command line? PHP 下载脚本在通过 AJAX 调用时不起作用 - PHP download script does not work when called via AJAX 从PHP调用的Shell脚本不起作用,但可以在命令行中使用 - Shell script called from PHP does not work, but it works in command line 相当于$ _SERVER ['DOCUMENT_ROOT'],当cron调用脚本时它会起作用? - equivalent to $_SERVER['DOCUMENT_ROOT'] that will work when script is called by cron? cron调用的PHP脚本未终止 - PHP script called by cron not terminating 手动调用时,php脚本可以完全正常运行,但不会从cron作业中运行 - php script works fully when called manually, but won't run from cron job PHP - 从 Cron 作业/命令行调用脚本时环境变量不可用 - PHP - Environment Variables Not Available When Script Called From Cron Job / Command Line 我的php脚本在由cron作业调用时未发送电子邮件 - My php script is not sending an email when called by a cron job
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM