So. I’m on wordpress.com hosting. So far so good. The problem is that I have a CLI command that needs to run twice daily. Unfortunately I have not found a way for setting up a proper cron job so I have tried the following:
function wenet_import_from_propstack() {
write_log('Cron Job Log: import_from_propstack_hook start');
wp_mail("[email protected]", "propstack cron gestarted staging", "wir starten jetzt gerade");
set_transient('wenet_import_from_propstack_cronjob', 'ja', 60*5); // Setzt den Transient für 5 Minuten.
$command = 'wp ps import > /dev/null 2>&1 &';
$output = shell_exec($command);
error_log("Ausgabe des WP-CLI Befehls: " . $output);
delete_transient('wenet_import_from_propstack_cronjob');
write_log('Cron Job Log: import_from_propstack_hook end');
wp_mail("[email protected]", "propstack cron fertig staging", $output);
}
add_action('import_from_propstack_hook', 'wenet_import_from_propstack');
if (!wp_next_scheduled('import_from_propstack_hook')) {
wp_schedule_event(time(), 'twicedaily', 'import_from_propstack_hook');
}
twice per day I get an E-Mail, but unfortunately the command is not called.
To make things even stranger. When I login via CLI and trigger the event manually:
wp cron event run import_from_propstack_hook
then it works. Why? Or differently asked. How can I periodically call a cli command on wordpress.com hosting?