I want to be able to run php script and then it should check itself to make sure X number of seconds have passed before it can run again. I am not talking about halting it's execution for x number of seconds using sleep() procedure.
For instance, a user clicks on a link to execute a PHP script. That php script shouldn't be allowed to run again until it has finished its execution and/or x number of seconds have passed, even if the user clicks the link again real quick like within a second.
I was thinking of creating a time difference flag and check it every time PHP script is called, but it doesn't seem to be working for me.
php file
//For the first time, it will skip over this block of code, because $timediff is not initialized yet.
if (isset($timediff))
{
if ((microseconds(true) - $timediff)<10) {
exit();
}
...
$timediff = microseconds(true);
...
But this doesn't work for me.
Any hints or help will be greatly appreciated. Thanks.
/yourserver/path/foo.php? In which case every execution is independent so your$timediffis not shared across runs. "because $timediff is not initialized yet" will always be true.