什么更快;包括另一个文件或在PHP中查询MySQL数据库? [英] What's quicker; including another file or querying a MySQL database in PHP?

查看:84
本文介绍了什么更快;包括另一个文件或在PHP中查询MySQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,更快;使用 include('somefile.php')或使用简单的 SELECT 查询查询MySQL数据库以获取相同的信息?

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

例如,假设您有一个JavaScript自动填充搜索字段,需要3,000个术语才能匹配。使用 include 从另一个文件中读取这些术语是否更快或使用简单的 SELECT 查询?

For example, say you had a JavaScript autocomplete search field which needed 3,000 terms to match against. Is it quicker to read those terms in from another file using include or to read them from a MySQL database using a simple SELECT query?

编辑:这假设我想要包含的数据库和文件与我的代码位于同一本地计算机上。

This is assuming that the database and the file I want to include are on the same local machine as my code.

推荐答案

这取决于。如果您的文件本地存储在服务器中并且数据库安装在另一台机器上,那么包含该文件的速度就越快。

It depends. If your file is stored locally in your server and the database is installed in another machine, then the faster is to include the file.

Buuuuut,因为它取决于您的系统这可能不是真的。我建议你制作一个PHP测试脚本并从命令行运行100次,然后通过HTTP重复测试(使用cURL)

Buuuuut, because it depends on your system it could be not true. I suggest to you to make a PHP test script and run it 100 times from the command line, and repeat the test through HTTP (using cURL)

示例:

use_include.php

<?php

  start = microtime(true);

  include( 'somefile.php' );

  echo microtime(true)-start;

?>

use_myphp.php

<?php

  start = microtime(true);

  __put_here_your_mysql_statements_to_retrieve_the_file__

  echo microtime(true)-start;

?>

这篇关于什么更快;包括另一个文件或在PHP中查询MySQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆