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

后端 未结 12 1696
闹比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 05:13

    Reading in raw data to a script from a file will generally be faster than from a database.

    However it sounds like you are wanting to query that data in order to find a match to return to the javascript. You may find in that case that MySQL will be faster for the actual querying/searching of the data (especially if correctly indexed etc.) as this is something a database is good at.

    Reading in a big file is also less scalable as you will be using lots of server memory while the script executes.

提交回复
热议问题