My PHP script are triggered via POST from different sources. There is a array, where elements are added and deleted.
I save this array with
$jsonString = json_encode($curList);
file_put_contents("curList.obj", $jsonString);
and read it with
$stringified1 = file_get_contents("curList.obj") ?: '';
$curList = json_decode($stringified1, true) ?: [];
This works usually fine. But now I got in trouble, because several instances are running at the same time and read and write the array in the same time period. This creates problems, because some information are going lost.
It is possible to make sure, that another instance has to be wait, until the read and update of the file is finished?
Or is it possible that only one instance of the script is running at the same time, without a POST get lost?