PHP code example of soderlind / dss-cron

1. Go to this page and download the library: Download soderlind/dss-cron library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

soderlind / dss-cron example snippets


   define( 'DISABLE_WP_CRON', true );
   

   define( 'ALL_SITES_CRON_AUTH_TOKEN', 'your-long-random-secret' );
   

add_filter( 'all_sites_cron_rate_limit_seconds', fn( $seconds ) => 120 ); // 2 minutes between runs

add_filter( 'all_sites_cron_number_of_sites', fn( $max ) => 500 ); // Cap total processed sites

add_filter( 'all_sites_cron_batch_size', fn( $batch ) => 25 ); // Smaller batches to reduce memory

add_filter( 'all_sites_cron_request_timeout', fn( $timeout ) => 0.05 ); // 50ms per site dispatch

// Force authentication even without a stored token
add_filter( 'all_sites_cron_

add_filter( 'all_sites_cron_redis_host', fn() => 'redis.internal' );
add_filter( 'all_sites_cron_redis_port', fn() => 6380 );
add_filter( 'all_sites_cron_redis_db', fn() => 2 );

add_filter( 'all_sites_cron_redis_queue_key', fn() => 'network_cron:jobs' );

add_filter( 'https_local_ssl_verify', '__return_true' );

// Process more sites in smaller batches
add_filter( 'all_sites_cron_number_of_sites', fn() => 2000 );
add_filter( 'all_sites_cron_batch_size', fn() => 25 );
add_filter( 'all_sites_cron_rate_limit_seconds', fn() => 180 ); // 3 minutes

// Faster processing with larger batches
add_filter( 'all_sites_cron_batch_size', fn() => 100 );
add_filter( 'all_sites_cron_rate_limit_seconds', fn() => 30 ); // 30 seconds

// More aggressive settings for testing
add_filter( 'all_sites_cron_rate_limit_seconds', fn() => 10 ); // 10 seconds
add_filter( 'all_sites_cron_batch_size', fn() => 5 );
add_filter( 'all_sites_cron_request_timeout', fn() => 0.1 );

// Old:
add_filter( 'dss_cron_number_of_sites', fn() => 300 );
// New:
add_filter( 'all_sites_cron_number_of_sites', fn() => 300 );

// Increase existing rate limit by 30 seconds (but cap at 300):
add_filter( 'all_sites_cron_rate_limit_seconds', fn( $seconds ) => min( $seconds + 30, 300 ) );

// Halve the batch size dynamically (never less than 10):
add_filter( 'all_sites_cron_batch_size', fn( $batch ) => max( 10, (int) floor( $batch / 2 ) ) );

// Scale the max sites based on environment variable:
add_filter( 'all_sites_cron_number_of_sites', fn( $current ) => getenv( 'ASC_MAX_SITES' ) ? (int) getenv( 'ASC_MAX_SITES' ) : $current );

// Add a safety floor for the request timeout (never below 0.01):
add_filter( 'all_sites_cron_request_timeout', fn( $timeout ) => max( 0.01, $timeout ) );

// Dynamically choose Redis queue key per environment (prefix existing):
add_filter( 'all_sites_cron_redis_queue_key', fn( $key ) => 'prod_' . $key );
json
{
  "success": false,
  "error": "rate_limited",
  "message": "Rate limited. Try again in 37 seconds.",
  "retry_after": 37,
  "cooldown": 60,
  "last_run_gmt": 1696071234,
  "timestamp": "2025-09-30 12:35:23"
}