is PHP quick to read the database in the template traversal or to read HTML from the file?

Source: Internet
Author: User
Tags redis server
Before doing a mall site, there is a module is customized home page, the time to drive the direct extraction of HTML content in PHP file, the first page read, then read the file output to the template. The read database of the topic refers to reading custom data, not HTML content.

I'm not in a hurry now, want to know:

    1. Is it faster to read a file if the concurrency is high in multiple people access? Or is it fast to read data from a database?

    2. If the file content is written more, the file is larger is not read time slow?

    3. I use the TP frame, directly in the template will not be better

    4. Ask again, how do you want to test the concurrency? What keywords do you want to search?

PS: Just came out to work the little white, beg to answer advice

Reply content:

Before doing a mall site, there is a module is customized home page, the time to drive the direct extraction of HTML content in PHP file, the first page read, then read the file output to the template. The read database of the topic refers to reading custom data, not HTML content.

I'm not in a hurry now, want to know:

    1. Is it faster to read a file if the concurrency is high in multiple people access? Or is it fast to read data from a database?

    2. If the file content is written more, the file is larger is not read time slow?

    3. I use the TP frame, directly in the template will not be better

    4. Ask again, how do you want to test the concurrency? What keywords do you want to search?

PS: Just came out to work the little white, beg to answer advice

    1. Database data is also present in the file, regardless of the database to do memory cache, the simple reading of the file is certainly faster than reading the database, because the database also through the query process and other processing processes. However, if you have too many files, you also need to consider the speed of the file system, which is slower than the database query when there are too many files.

    2. The file read time naturally depends on the size of the file, but if everything in the file is what you want, this time is naturally indispensable. If you only want to read part of the file content, you can move the file pointer through seek.

    3. TP Framework template is compiled, that is, the actual execution will not use the template file you write, but the use of the compiled template, so you can rest assured that the use of include, do not care about the performance of the problem.

    4. Concurrency tests should be called stress tests, and search for stress test scenarios.

In response to your question,

    1. In the case of high concurrency, the direct database will certainly be slow, at least there is a cache layer on the database, the cache layer efficiency:

      文件 < 内存(memcache、redis) < Cache阵列文件也属于Cache的一种

      Look at your needs. There are also steps to generate a static file, here are a few keywords:

      • ob_start

      • 伪静态

      • CDN

    2. If you write more files, this is not a way, we generally use the cache and so on to do the overall architecture scheme, rather than simply write so simple

      If the read file (specifically PHP file) is larger, consider opening Opcache to enhance the speed

    3. You include a template file, which PHP executes, which is the include same efficiency as PHP include .
      SSI ( Apache , nginX ) is include much faster than PHP if you are accessing a page with all static files and need to embed a sub-template

      So, the answer to your question: HTML is the fastest, no PHP is needed, but it needs to be built in advance.

    4. Concurrency testing, apache benchmark starting with keywords, you'll find a lot of what you want.

First of all, their speed difference is not big, file fast, but if you put the database good management.

Second, who is not important, these CMS types of Web sites, can be static to optimize, after the static and page generation time is irrelevant.

First, memory >> file
Second, the database is also the data stored in the file (of course, the database has a query cache)
Non-relational data is, of course, the file is stored fast
However, a large number of files cannot be stored under the same folder (slow addressing) and can be split using file name directories, such as:
File name Dsaferdfsasxfsfsdf.dat
Take the first two characters to create a first level directory, stored as
Ds/dsaferdfsasxfsfsdf.dat
Lokljljoiomlkml.dat >> Lo/lokljljoiomlkml.dat

TP comes with a simple cache method s (), the default is file-driven, if the cache driver with memcahced or redis, it should be faster than the file, provided that the memached or Redis server on this computer, or in the gigabit LAN

For concurrent testing, the Linux and Darwin (OS X) kernel systems can be used with the AB command (Apachebench), such as:
Ab-k-N 1000-c "http://www.baidu.com"
1000 requests are initiated, each concurrent 100 (the value will have an upper limit, depending on the system settings, the default is 256)

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.