简体   繁体   English

我如何每2小时在Amazon EC2云上运行php脚本?

[英]How do i run a php script every 2 hour on amazon ec2 cloud?

I am trying to run a php script every hour on amazon ec2 cloud but not able to run it. 我试图每小时在Amazon EC2云上运行一个php脚本,但无法运行它。 I am using it 我正在使用

MAILTO="email@something.com"
* */2 * * * /usr/bin/php /var/www/html/sports/webservices/cron-job.php

I have also mentioned my email in MAILTO . 我还在MAILTO提到了我的电子邮件。 But not receiving any email and it is not updating the database. 但是没有收到任何电子邮件,也没有更新数据库。

When i changed (removed /usr/bin/php ) it with this 当我更改(删除/usr/bin/php )时,它与此

MAILTO="email@something.com"
* */2 * * * /var/www/html/sports/webservices/cron-job.php

then I received an email with this error message. 然后我收到一封包含此错误消息的电子邮件。

/var/www/html/sports/webservices/cron-job.php: line 1: ?php: No such file or directory
/var/www/html/sports/webservices/cron-job.php: line 2: syntax error near unexpected token `0'
/var/www/html/sports/webservices/cron-job.php: line 2: `error_reporting(0);'

Your problem is that a cronjob is normally executes as sh script. 您的问题是cronjob通常作为sh脚本执行。 So you need to let the php script been executed by the php interpreter. 因此,您需要让php脚本由php解释器执行。 Try to use: 尝试使用:

* */2 * * * /bin/php5 /var/www/html/sports/webservices/cron-job.php

Please note that the php binary can also be php in the directory /usr/bin/ . 请注意,php二进制文件也可以是目录/usr/bin/中的php

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM