I'm trying to make a mission system where users can accept a mission or not, and if it hasn't been accepted after X minutes it will be inactivated. Is this a good way to do it, would it be able to handle 10K missions per day?
<?php
$mission_id = htmlspecialchars($_POST["mission_id"]));
$user = $_SESSION["user"];
// Verify that user is same as mission agent
$verify = $conn->prepare("SELECT agent FROM missions WHERE id = ? AND active = 0 ORDER BY id limit 1");
$verify->bindParam(1, $user);
$verify->execute();
$verify = $verify->fetch(PDO::FETCH_ASSOC);
if($verify["agent"] == $user) {
unset($verify);
// Do time code.
ignore_user_abort(true);
set_time_limit(300);
$time = 0;
while(time < 300) {
sleep(15);
time += 15;
// check if mission was accepted
$verify = $conn->prepare("SELECT accepted FROM missions WHERE id = ? ORDER BY id LIMIT 1");
$verify->bindParam(1, $mission_id);
$verify->execute();
$verify = $verify->fetch(PDO::FETCH_ASSOC);
if($verify["accepted"] == 0) { // not accepted
unset($verify);
// Inactivate mission
$inactivate = $conn->prepare("UPDATE missions SET active = 0 WHERE id = ?");
$inactivate->bindParam(1, $id);
$inactivate->execute();
unset($inactivate);
}
else {
break;
}
}
}
else {
header("location: logout.php");
// Log user out
}
?>