How to prevent access to the page until the process is initiated by other visitors? On one website I have hidden page what I trigger with cron job in particular time. On that page is script what generate daily email and send on 50.000 email adresses. That script inside it have pagination what I use to made group of sequences by 2000 users per each session. I find that sometimes cron job trigger page multiple times and I need to trigger only once. Also some Google and Bing spider find page in the same time when access cron job and trigger multiple times. I need prevent multiple triggers in the same time.
Here is main part of code for you to understand functionality of that page:
/* Start Class
===============================*/
global $$dbConn, $prefix, $config;
$dr = new prDailyRequests($dbConn, $prefix, false);
if($dr->send)
{
$page = isset($_GET["page"]) ? $_GET["page"] : $dr->page;
$lastpage = $dr->total;
/* Redirect on pagination
===============================*/
if(!isset($_GET["page"]) || !isset($_GET["total"]))
{
usleep(10);
header("HTTP/1.1 303 See Other");
header("Location: ".$config->url."/index.php?component=request&option=trigger&page=".($page)."&total=".($lastpage));
exit;
}
/* Send request on email
===============================*/
else if($page <= $lastpage)
{
$page=$dr->send();
usleep(10);
header("HTTP/1.1 303 See Other");
header("Location: ".$config->url."/index.php?component=request&option=trigger&page=".($page)."&total=".($lastpage));
exit;
} else die();
} else {
header("HTTP/1.1 200 OK");
exit;
}
In class new prDailyRequests()
I have a functionality for collecting daily posts and user emails from site database, generate email template and send into InfusionSoft in sequence of 2000 users per page. I use database to store session and information when is send daily requests, how many users and in which page is the current script. Here is fields in database:
id | total_users | current_page | totla_page | day | month | year | timestamp
Do can help me PHP function register_shutdown_function()
or I need to use some another approach?
For you to be clear, here is one example:
If I trigger that script and that script running, that script can work arround 30-40s. In that time when script work I need stop other visitor to trigger same script. I need prevent access to other visitors on that page while script work.
Thanks!