Answer the question
In order to leave comments, you need to log in
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"
}
Answer the question
In order to leave comments, you need to log in
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.
In fact, if the file is very large and has a regular structure, then you can use the grep system command
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.
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 questionAsk a Question
731 491 924 answers to any question