I have N devices sending their data via HTTP (POST) requests all to the same URL (lets call it 'upload.php'). Every minute, around 100-150 POST requests are made to upload.php. Suppose for the sake of example that the devices spotted balloons and sent out this data:
[ {
"timestamp" : 1507320877294,
"color" : "red",
"balloon" : {
"x" : 42,
"y" : 312,
"z" : 287,
}
} ]
..
[ {
"timestamp" : 1607320877294,
"color" : "yellow",
"balloon" : {
"x" : 42,
"y" : 312,
"z" : 287,
}
} ]
I have a table in a database that looks like this and aggregates the data the following way:
+---------------------------------------------------------------------+
| spotter_sensor_id | hour_collected | red_balloons | yellow_balloons |
+---------------------------------------------------------------------+
| 992 | 17:00:00 | 5 | 5 |
+---------------------------------------------------------------------+
I don't want to make an update/insert query each time upload.php receives a post request. I'd rather temporarily store the data and then every 10 minutes or so make one query like:
INSERT INTO table
(spotter_sensor_id, hour_collected, red_balloons, yellow_balloons)
VALUES
('992', '$hour_collected', '$red_balloons', '$yellow_balloons')
ON DUPLICATE KEY UPDATE
red_balloons = $red_balloons + VALUES(red_balloons),
yellow_balloons = $yellow_balloons + VALUES(yellow_balloons);
...that holds how many balloons were spotted for each sensor during those 10 minutes.
What are my options for storing intermediate data from upload.php to another script (lets call it 'send.php') using PHP 7? Preferably an option where data deadlocking or concurrency won't be an issue?
Note: my environment is Windows Server 2016 with PHP 7. I have looked at OPCache but I haven't found a DLL that works for PHP 7—an unofficial one I forked off GitHub has been very buggy.