0
I have the following code:
$newprice = $ob->pennyauction == 1 ? $oldprice + 0.01 : $oldprice + $plusprice;
I need it to perform the following check, before displaying the value of $newprice
.
The rule is to prevent the same value being written to DB, for example if in $oldprice
you already have 0.02 and he tries to record the 0.02 again, the rule should add + 0.01.
He already does it there, but sometimes it happens to run at exactly the same time, then he inserts the same values, then enters this rule to validate it.
There’s something to implement there?
Will depend, run at exactly the same time .. you mean multiple users at the same time ? Or you are running a loop ?
– NoobSaibot
Multiple users at the same time.
– Wendler
When running add in a server side execution queue instead of running on time should prevent this
– AnthraxisBR
@Anthraxisbr Do you have any examples of this? I have no idea what it is.
– Wendler
See if this resolves: https://www.exakat.io/prevent-multiple-php-scripts-at-the-same-time/ lock file is simpler than creating that list
– AnthraxisBR
Boy, I read everything on that website and I don’t understand exactly what it’s gonna do. Will prevent the file from running at the same time by users?
– Wendler
Yes, when running a script, creating a file and when finished it removes, and if you try to run at the same time it tries to create that file, if it exists it does not let run, I will make a response.
– AnthraxisBR