A
A
Artem Prokhorov2021-07-22 20:05:41
PHP
Artem Prokhorov, 2021-07-22 20:05:41

Which is faster: file_get_contents to json file or query to db?

As far as I understand, it depends on how heavily the jsonfile is filled, but then again, MB, who knows the articles are sensible or will they write it themselves?
What should be the weight of jsonthe file to be more efficient than a database query? Can I have some specific numbers?
PS
I ask this, since there are conditional sockets for chats, in the same place it is unlikely that every message is immediately recorded in the database (or is it done?).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2021-07-22
@kotcich

the question is completely stupid. both in content and purpose.
speed - in the vast majority of cases, it is not a criterion at all.
The criterion is ease of use.
I point with my fingers:
ten times faster. sounds cool, right?
and if we take it not relatively, but absolutely: how much faster is 0.001 seconds in the context of the web than 0.01 seconds?
you won't notice this difference at all until you have millions of hits at least an hour.
and if you are so restless to get an answer, then take measurements. because the measurements of others have nothing to do with your conditions.

S
Sergey Sokolov, 2021-07-22
@sergiks

there are conditional sockets for chats, in the same place it is unlikely that every message is directly in the database immediately

for sockets and speed, you can keep everything in memory: when a message arrives, it immediately goes to the recipients, plus the task to write this message to the database for the comrade major of those who are offline is queued later. Slightly different architecture: events, coroutines. In the context of PHP, look at Swoole.
JSON file can be used for some rarely changing data, settings. For example, for key-signing-settings for access to some third-party API. With a DB I would not compare. JSON must be read and parsed; The database keeps all files open, ready, just rewind to the desired position. In a DB caching and optimization everyone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question