簡體   English   中英

安排Crontab運行PHP腳本

[英]Schedule Crontab for running PHP script

我試圖通過cron選項卡在路徑/var/www/html/rss_feed/mirror.php上運行PHP文件。 為此,我執行了以下步驟。

sudo crontab -e

然后我通過插入以下代碼編輯了該文件

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# 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
# avt 5 a.m every week with:
# 0 5 * * 1 tar -zcf /ar/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
*/2 * * * * /usr/bin/php /var/www/html/rss_feed/nbt_times.php
#
# m h  dom mon dow   command

正如您在下面看到的那樣,插入代碼行以在每2分鍾運行一個php文件后安排cron選項卡。

*/2 * * * * /usr/bin/php /var/www/html/rss_feed/nbt_times.php

我甚至試過跟隨

2 * * * * lynx -dump http://192.168.0.232/rss_feed/mirror.php > /dev/null 2>&1

甚至這個

2  * * * * /your/path/to/php /var/www/html/rss_feed/nbt_times.php

以及來自不同文章的更多格式。

php腳本沒有運行。 我需要將代碼放在其他地方嗎? 或者我走錯了路。 您能幫我找出問題所在嗎?

它應該工作,但需要在這里得到一些澄清,文件名似乎不同一次它的mirror.php和另一次它的nbt_times.php

哪個php文件必須在必須指定的特定時間運行。 正如您指定的那樣,您正在運行/var/www/html/rss_feed/mirror.php,然后在第一個命令上指定mirrror.php。

第2和第3個命令將在每小時的第2分鍾運行作業。 喜歡(4:02,5:02,6:02等)

試試這個crontab

*/2 * * * * /usr/bin/php /var/www/html/rss_feed/mirror.php

這將每2分鍾運行一次,希望這有效。

嘗試使用php5-cli:

*/2 * * * * /usr/bin/php5-cli -f /var/www/html/rss_feed/nbt_times.php

還要添加寫入日志,並在幾分鍾后查看它們:

* * * * * /usr/bin/php /var/www/html/rss_feed/nbt_times.php >>log.log 2>>log.err

檢查php文件的權限。 使0777進行檢查。 嘗試用一行創建最簡單的php文件並通過cron運行它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM