Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter aaronroneill

    (@aaronroneill)

    Hi Slava,

    Apologies for the delay in getting back to you. Here is the code to my sample script which the server cron runs. This script with any plugin version 0.11.1 or newer causes a root@localhost error.

    As you can see it’s a very simple one file plugin that just schedules an email every 5 minutes, the server cron then sends the email.

    <?php
    /*
      Plugin Name: Cron Tester 
      Plugin URI:  #
      Description: Simple cron task - check to see cron is running correctly
      Version:     1.0
      Author:      Aaron
      Author URI:  #
    */
    
    class aCronTester {
    
      function __construct() {
    		
    		# Actions:
    		add_action( 'a_test_cron', array( $this, 'send_mail' ) );
    
    		# Activation:
    		register_activation_hook( __FILE__, array( $this, 'activate' ) );
    		register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
    
    	}
      
      function send_mail() {
        
        echo 'Cron Tester: send_mail() run! <br><br>';
        error_log("Cron Tester Has Been Run: " . date('Ymd-H:i:s'), 0);
        
        $mail = wp_mail( '[email protected]', 'a Cron Tester Run' . date('Ymd-H:i:s'), 'The Cron Tester has been run...'  . date('Ymd-H:i:s'), '', array() );
        
        error_log($mail);
        echo 'Mail sent? ';
        var_dump($mail);
        
      }
    
      function activate() {
    		wp_schedule_event( time(), 'every5min', 'a_test_cron' );
    	}
    
    	function deactivate() {
    		wp_clear_scheduled_hook( 'a_test_cron' );
    	}
    
    }
    
    add_filter('cron_schedules','cron_add_every_five');
    
    function cron_add_every_five($schedules){
    	$schedules['every5min'] = array(
    		'interval' => 300,
    		'display' => __( 'Once every 5 minutes'),
    	);
    	
    	return $schedules;
    }
    
    $acrontester = new aCronTester;
    ?>
    Thread Starter aaronroneill

    (@aaronroneill)

    Hi Slava,

    Thanks for getting back to me. It’s configured as below.

    */30 * * * * /usr/local/php70/bin/php-cli /home/public_html/wp-cron.php >/dev/null 2>&1

    As you can see, there is nothing too fancy about it as it is just configured to run wp-cron.php every 30 mins using PHP7.

    I have also checked to ensure SHORT_INIT is not defined anywhere.

Viewing 2 replies - 1 through 2 (of 2 total)