A
A
Alexander2018-09-17 09:57:38
PHP
Alexander, 2018-09-17 09:57:38

How to test a large array?

There is a json file, where there are many many users, there are password lines, email. Looks like this:

{
"uid":"1000", 
"name":"[email protected]", 
"pass": "321"
}
{
"uid":"1001", 
"name":"[email protected]", 
"pass": "123"
}

How to sort through this entire array during authorization to check if the email and password match?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey Sokolov, 2018-09-17
@sergiks

PHP may crash during the step json_decode()if the json file is too large.
Therefore, it is better to translate all the data once into something suitable for the task: MySQL, Mongo, Elasticsearch, or something else .
A hell of a bike, it's reading a json file line by line and parsing it manually, without json-decode. It will save you from lack of memory, it will be slow and creaky.

D
dilshod_developer, 2018-09-17
@dilshod_developer

You can use array_filter

V
Vasily Andreev, 2018-09-18
@PyroRed

In fact, if the file is very large and has a regular structure, then you can use the grep system command

V
Vadim, 2018-09-19
@denisovvsh

You do not have an array, but an object, because brackets {}, in the array brackets []. You can try to use the Array.prototype.find() function
https://developer.mozilla.org/en/docs/Web/JavaScri...
Of course, it's better to use a database.
It is not safe to store account passwords in this form.

P
Petr Vasiliev, 2018-09-19
@danial72

you have 2 ways:
1) use the json encode function - parse the file with this function.
, iterate over the objects and find the desired object.
2) read the file line by line, and look for login entries, then determine the line in which the password is located and check,
but the most reasonable move to the database. If it's important to do on files : sqlite

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question