E
E
Eugene2020-04-19 22:52:37
PHP
Eugene, 2020-04-19 22:52:37

How to search on a large json file?

Hello.
There is a file with a base of post offices of new mail, which is stored in json format. The file itself contains several thousand entries. How can search by key be organized in such a way that it would spend less resources?
Solutions like this result in a 504 error on my laptop. I also used generators, the situation does not change

$findByRef = function($ref) use ($objitems) {
    foreach ($objitems as $warehouse) {
        if ($warehouse->Ref == $ref) return $warehouse->description;
     }

    return false;
};

json example
{
  "success": true,
  "data": [{
    "SiteKey": "19709",
"Description": "\u041f\u0443\u043d\u043a\u0442 \u043f\u0440\u0438\u0439\u043c\u0430\u043d\u043d\u044f-\u0432\u0438\u0434\u0430\
       ...........................
  }, {
    "SiteKey": "18142",
    "Description": "\u041f\u0443\u043d\u043a\u0442 \u043f\u0440\u0438\u0439\u043c\u0430\u043d\u043d\u044f-\u0432\u0438\u0434\u0430\
..............

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2020-04-19
@Eugene70

Have you tried using a database for this purpose?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question