简体   繁体   English

读取列表并将其存储为数组

[英]reading and storing a list as an array

I have a script that receives json data from various sources and processes it.我有一个脚本,可以从各种来源接收 json 数据并对其进行处理。 I have a list in a database and also as a text file of known good sources.我在数据库中有一个列表,也有一个已知良好来源的文本文件。 The list has thousands of records.该列表有数千条记录。

Before processing I want to compare the source value from json with the source value in the list.在处理之前,我想将 json 中的源值与列表中的源值进行比较。 Data is received every 10 sec.每 10 秒接收一次数据。 The list does not change often.该列表不会经常更改。

At the moment I can make this work either by querying the database for the sources list or read the list from a text file, however it seems redundant to do this every 10 sec upon receiving json since the list is going to be the same 99% of the time.目前我可以通过查询数据库中的源列表或从文本文件中读取列表来完成这项工作,但是在接收到 json 时每 10 秒执行一次似乎是多余的,因为列表将是相同的 99%的时间。

The question is - what is the good way to do this?问题是 - 这样做的好方法是什么?

Assuming this DB is something you have more than read access - you mentioned the database records do not change often, you could add a trigger on the DB for any changes.假设这个数据库不仅仅是读取访问权限 - 您提到数据库记录不经常更改,您可以在数据库上添加触发器以进行任何更改。 Have the trigger update a single row in a new table called "listUpdated" to True.让触发器将名为“listUpdated”的新表中的一行更新为 True。 Load the list into an array in your PHP and use that to bump your data against.将列表加载到 PHP 中的数组中,并使用它来碰撞您的数据。 Every 10 seconds you can just check if the "listUpdated" field has been set to True.每 10 秒您可以检查“listUpdated”字段是否已设置为 True。 If it is, update your array and change the value back to False.如果是,请更新您的数组并将值更改回 False。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM