LoginSignup
0
1

More than 3 years have passed since last update.

[WordPress] Docker 環境下の wp-cron.php を cron で実行する方法

Last updated at Posted at 2020-02-14

WP-Cron(wp-cron.php)とは?

WP-Cron works by: on every page load, a list of scheduled tasks is checked to see what needs to be run. Any tasks scheduled to be run will be run during that page load. WP-Cron does not run constantly as the system cron does; it is only triggered on page load. Scheduling errors could occur if you schedule a task for 2:00PM and no page loads occur until 5:00PM.

WP-Cronは次のように機能します。ページをロードするたびに、スケジュールされたタスクのリストをチェックして、実行する必要があるものを確認します。実行がスケジュールされているタスクは、そのページのロード中に実行されます。 WP-Cronは、システムcronのように常に実行されるわけではありません。ページの読み込み時にのみトリガーされます。午後2時のタスクをスケジュールし、午後5時までページの読み込みが行われない場合、スケジューリングエラーが発生する可能性があります。

https://developer.wordpress.org/plugins/cron/#why-use-wp-cron

WordPress のコアファイルの一つの wp-cron.php はアクセストリガーで実行します。その結果、トラフィックが少ないサイトだと正しく予約投稿が動作しない問題が発生します。

そこで、アクセストリガーの cron である WP-Cron を停止して、Docker コンテナ内で cron が動作するようにしました。

以下、備忘録です。

概要

1. アクセストリガーの WP-Cron を停止

2. Docker 環境下で cron が動作するように設定

3. wp-cron.php を 1 分に 1 回のペースで叩くスケジュールを登録

やったこと

WordPress


define('DISABLE_WP_CRON', 'true');

Docker


apt update

apt install cron

apt install vim

export EDITOR=vim

/usr/sbin/cron -f &

crontab -e

*/1 * * * * /usr/local/bin/php /var/www/html/wp-cron.php

:wq!
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1