how i can prevent multiple execution of a REST API in same time... i have a rest API with several MySQL database operation... when API call from multiple devices on same time ,that will make several issues in my MySQL operations in rest API [PHP file] ...
How i can fix that ? any suggestions ? consider.. i am a beginner
My REST API code:
<?php
$receipt = $_POST["receipt"];
$maxselect = $_POST["maxselect"];
$user = $_POST["user"];
$pass = $_POST["pass"];
$trans = $_POST["trans"];
include("dbConnect.php");
$result=mysqli_query($conn,"SELECT emp_pass FROM emp WHERE emp_name ='$user'");
$affected = mysqli_affected_rows($conn);
if ($affected > 0) {
#USER DETAILS MATCH
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$password = $row['emp_pass'];
}
}
if(strcmp($pass, $password) !== 0) {
$response = false;
echo json_encode($response);#encoding RESPONSE into a JSON and returning.
mysqli_close($conn);
exit();
}
// $randomtime =rand(0,2000000);
// usleep($randomtime);
$check=mysqli_query($conn,"CALL saveReceipt('$maxselect','$receipt','$trans')");
$response = true;
echo json_encode($response);#encoding RESPONSE into a JSON and returning.
mysqli_close($conn);
exit();
?>