首页 > 解决方案 > 运行 .php 文件的 Cron 作业失败

问题描述

我有一个问题。Raspberry Pi 与 Raspberry Pi OS Lite。我有一个位于 /var/www/html/bloomsky.php 的 .php 文件

这个 .php 文件只是要求每隔 1 分钟从 AmazonAWS 服务器下载一个新图像(以 1 分钟测试,但将来会达到 5 左右)当我访问该网站并将其直接指向Bloomsky 时.php 文件,然后 PHP 文件确实可以下载更新的图像并覆盖 /var/www./html/image.jpg 中存在的图像

当我检查 image.jpg 文件的时间戳时,它显示了bloomsky.php 文件伸出手并抓取一个新文件并覆盖它的当前时间。

所以 PHP 文件按预期工作。所以我创建了一个 cron 作业来定期运行该 bloomsky.php 文件。用于Crontab -e创建条目 这里是整个文件

#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).

# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
 * * * * * root /usr/bin/php /var/www/html/bloomsky.php

我也试过

 * * * * * root /var/www/html/bloomsky.php

保存这些更改后,我也重新启动了。

如果 Cron 作业每分钟都正常工作,它将启动Bloomsky.php文件并下载并覆盖image.jpg文件,从而更新其时间戳详细信息。

那没有发生。我还制作了该文件的副本Bloomsky.php并将其放在我的主目录中。

标签: phpcron

解决方案


推荐阅读