Skip to content
Advertisement

How to run scheduled code without user manipulation

In WordPress, I want to do the licensing system for plugins and theme that I write. I have no problem entering the key and checking it, but I want the key to be checked in a schedule of, say, 12 hours. I want the user to not be able to change it. If I use cron, the user will be able to change it by installing a plugin. Another way came to my mind was to save the last check in the database and check the last check time in my plugin or template was loaded each time, and if it was past, the key would be checked, but in this way the user can write a plugin and load it Earlier than my plugin or theme. Or my template loads and that plugin constantly pulls the last check time forward, so my plugin or theme doesn’t check the license. If anyone has a solution, thank you for giving it to me. Thank you in advance.

Advertisement

Answer

I have one suggestion, check if it is good for you.

You can use a “lottery script” (inpired by Laravel).

The idea is that the script checker will be executed randomically, so it not will consume the server all time but you will keep having one script that depends only of itsef.

$lottery = rand(1, 100);
if($lottery <= 2)
    echo 'check license';
else
    echo 'sleep ...';
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement