What's quicker; including another file or querying a MySQL database in PHP?

后端 未结 12 1858
闹比i
闹比i 2021-01-12 04:29

In PHP, which is quicker; using include(\'somefile.php\') or querying a MySQL database with a simple SELECT query to get the same information?

12条回答
  •  滥情空心
    2021-01-12 04:57

    It's very hard/impossible to give an exact answer, as there are too many unknown variables - what if the filesystem is mounted on an NFS that resides on the other side of the world? Or you have the whole MySQL database in memory. The size of the database should be factored in too.

    But, on a more answer-y note, a safe guess would be that MySQL is faster, given good indexes, good database structure/normalization and not too fancy/complex queries. I/O operations are always expensive (read: slow), while, as previously mentioned, the whole dataset is already cached in memory by MySQL.

    Besides, I imagine you thought of doing further string manipulation with those included files, which makes things even more troublesome - I'm convinced MySQL's string searching algorithms are much better optimized than what you could come up with in PHP.

提交回复
热议问题