Wordpress-WordPressの 'Cron'wp_schedule_eventをデバッグする方法



Wordpress How Debug Wordpresscronwp_schedule_event



解決:

以下を呼び出すことにより、WPcronを手動で実行できます。http://example.com/wp-cron.php?doing_wp_cron

デバッグ中に自動cronを実行したくない場合は、これを/wp-config.phpファイル:



define('DISABLE_WP_CRON', true);  

If you're on a development environment and want to output debug information, calling it manually like that will show you your debug output.

Alternatively you can use PHP's built-in error_log function to log message strings to the error log for debugging. You'd need to use this in conjunction with WP_DEBUG settings, as mentioned by Rarst.




You could use the plugin Cron-View. There you can see if your job is a) registered and b) what the next due time is.

In addition, you could add a lower schedule-timer to your event (e.g. every 2 min) and test your method more frequently on a local system. Use the 'cron_schedules' filter hook to register new schedule times. For example:

function my_additional_schedules($schedules) { // interval in seconds $schedules['every2min'] = array('interval' => 2*60, 'display' => 'Every two minutes'); return $schedules; } add_filter('cron_schedules', 'my_additional_schedules'); 

アクションを作成し、内部でCronアクションを実行することにより、手動でデバッグできます。このような:



add_action( 'init'、function(){if(!isset($ _GET ['the_cron_test'])){return;} error_reporting(1); do_action( 'this_is_cron_event_hook'); die();});

そしてあなたのウェブサイトのアドレスに行くことによって:http://example.com?the_cron_test

これにより、cronタスクのエラーが表示されます。

しかし、手動で行うのは意味がありません。これを実行し、ログやその他の統計情報を保存するAdvanced Cron ManagerPROプラグインを使用できます。