I am doing some sort of cronjob inside a WordPress plugin that does the following. When the cronjob needs to be fired, it sends a piece of jquery code with the user that happens to visit. As soon as the script is loaded on the frontend, it sends a post back to the server with the actions that need to be performed.
Now the function that fires on the server takes a long time to complete, that's why I do it this way. In PHP i have ignore_user_abort(true);
so it does not matter if the user closes the browser. And I have some build in fallback if for some reason the actions are not fired with the particular user.
This works great all, only problem, for the particular user that visits, the browser keeps waiting for a reply. Is there a way I could break the jQuery post as soon as it is received by the server.
And if someone has another better solution for me to mimic a cronjob please let me know. I do not want to rely on functions as exec()
, pcntl_form
, wp-cron
, as they are often disabled for users.