Skip to content
Sign Up For Free
BatchKeys License Key SaaS
  • Pricing
  • Try Demo
  • Docs
  • SupportExpand
    • Tickets
  • AboutExpand
    • Contact
  • Dashboard
BatchKeys License Key SaaS

Getting Started

11
  • Setting Up An Account
  • Your Dashboard
  • Generating Keys
  • Viewing And Editing Keys
  • Viewing/Editing An Individual Key’s Details
  • Bulk Deleting Keys
  • Importing Keys
  • Encoding And Decoding PHP
  • Handling Refunds
  • Unbanning A Valid End User
  • Requesting An Enterprise or Custom Plan

Integrations

14
  • Inserting Code Into Your App
  • Making API Calls
  • Receiving A Response
  • Example JSON Response
  • Assigning Keys To A Domain Name
  • Generating Unique UUIDs
  • Assigning Keys To A UUID
  • Checking Keys Daily Using A Cron Job
  • Checking Keys At Startup
  • Consuming And Topping Up Tokens For Token-Based Keys
  • Server-Side Proxy For Client-Side JavaScript Connections
  • Forms To Collect A Key
  • Adding BatchKeys To A WordPress Plugin
  • Adding BatchKeys To A WordPress Theme

Best Practices

13
  • Using Domain/UUID Settings To Upsell Your App
  • Staying Within Rate Limits
  • Handling Errors
  • Dealing With Connection Failures And Rechecks
  • Securing Keys
  • Working Around Hardware Changes With V5 UUIDs
  • Working Around V4 UUID Security Concerns
  • Creating Good Validation Forms
  • How We Use UUIDs To Secure Keys
  • A Note About Example Codes
  • Can We Create Custom Code For You?
  • Maximum Key Limits Per Plan
  • Using A License Key Service In A Mobile App
  • Home
  • Docs
  • Integrations
  • Checking Keys Daily Using A Cron Job

Checking Keys Daily Using A Cron Job

It is recommended to check the end user’s key daily. This is important for handing refunds and dealing with malicious users who break your service agreement.

If your app is a web app, or will be installed on a webserver, or is part of a website, such as a plugin or theme, you should set up a simple cron job to do run daily.

NOTE: If your app is a stand-alone program with a clearly defined startup or launch event like a piece of windows/mac software or a video game, you should check the key during startup instead. See our full documentation to checking keys at startup to learn how to do that.

Getting The Key #

When your app first activates a key, it’s best practice to save the key from the user input into a secure local file or database. From this data you can preform key checks any time you need.

Creating A Pseudo Cron #

Most apps will be installed across a variety of dedicated servers and shared hosting environments, many of which have strict limitations on cron job creation. Since you will not be able to reliably create a server cron job programmatically, the best solution is to create a pseudo cron.

Create a file that is installed with your app with similar code to the below example. Note that we use PHP in these examples but this can be accomplished in any language.

$last_run_file = 'last_run.txt';
$last_run = file_get_contents($last_run_file);

// Check if the script has been run today
if (date('Y-m-d') !== $last_run) {
    // Run the daily tasks
    include('key_check.php');

    // Update the last run date
    file_put_contents($last_run_file, date('Y-m-d'));
}

This file will save the last time it ran to a local file, and if it’s been more than 24 hours since it last ran it will run now and save the new time. If it’s been less than 24 hours it will do nothing.

The file key_check.php is where your actual key check logic should be. Be sure to include this file in a major part of your app that will run often, like so:

// footer.php (or another frequently accessed file)

include('pseudo_cron.php');

WordPress Plugins And Themes #

If your app is a WordPress plugin or theme you’re in luck as they already have a pre-built pseudo cron called Wp-Cron. You can use WordPress hooks to create a cron job.

WordPress, Using PHP: #

function my_plugin_activate() {
    if (!wp_next_scheduled('my_plugin_daily_license_check')) {
        wp_schedule_event(time(), 'daily', 'my_plugin_daily_license_check');
    }
}
register_activation_hook(__FILE__, 'my_plugin_activate');

It’s also good practice to always clean up your cron jobs on an uninstall, so use something similar to this example.

function my_plugin_deactivate() {
    $timestamp = wp_next_scheduled('my_plugin_daily_license_check');
    wp_unschedule_event($timestamp, 'my_plugin_daily_license_check');
}
register_deactivation_hook(__FILE__, 'my_plugin_deactivate');
Was this Helpful?
Still stuck? How can we help?

How can we help?

Updated on April 4, 2024
Assigning Keys To A UUIDChecking Keys At Startup

Powered by BetterDocs

Table of Contents
  • Getting The Key
  • Creating A Pseudo Cron
  • WordPress Plugins And Themes
    • WordPress, Using PHP:
  • Get Early Access
  • Try Demo
  • Status
  • API Tester
  • Docs
  • Support
  • Feature Request
  • Feedback
  • About
  • Contact
  • Sitemap
  • Coupons

TOS

Privacy Policy

SLA

© 2025 Batch Keys | Created and maintained by Kayce Media Group

  • Pricing
  • Try Demo
  • Docs
  • Support
    • Tickets
  • About
    • Contact
  • Dashboard