I have a function which adds a new blog post to my database.
After running add_new_post() function the post should be approved by my another function approve_post().
But I don't want to approve post immediately. I want to run approve_post() function in time between 1 to 5 minute (random)
.
Now I am using this code:
function add_new_post() {
*my code of adding post*
$time = rand(60, 300);
echo $time;
sleep($time);
approve_post();
}
But browser shows loading until sleep ends. Also, I found that my Windows machine shows time execution error.
Is there a way to run approve_post()
function in the background without showing page loading to the browser?
I would be grateful for а code example.