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:
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?
If the file content is written more, the file is larger is not read time slow?
I use the TP frame, directly in the template will not be better
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:
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?
If the file content is written more, the file is larger is not read time slow?
I use the TP frame, directly in the template will not be better
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
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.
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.
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.
Concurrency tests should be called stress tests, and search for stress test scenarios.
In response to your question,
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:
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
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.
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)