To measure the acceleration of the slider on the air cushion guide rail, how to increase the speed of PHP Page 1/3

WBOY
Release: 2016-07-29 08:36:26
Original
1006 people have browsed it

Simple data caching technology
I have been doing optimization work on program performance for a while recently, and I have an interesting idea that I would like to share with you.
 Cache is a typical application mode of the "space for time" strategy, and is an important method to improve system performance. The use of cache can greatly reduce the number of database operations in the case of large access volumes, significantly reducing system load and improving system performance. Compared with page caching, the result set is a kind of "raw data" that does not contain format information. The amount of data is relatively small and can be formatted again, so it is quite flexible. Since PHP is a "compile and execute at the same time" scripting language, it also provides a very convenient way to use result set caching to a certain extent - using the cache by dynamically including the corresponding data definition code segment. If a cache is built on "RamDisk", the efficiency should be further improved. Below is a small sample code for reference.
// load data with cache
function load_data($id,$cache_lifetime) {
// the return data
$data = array();
// make cache filename
$cache_filename = 'cache_'. $id.'.php';
// check cache file's last modify time
$cache_filetime = filemtime($cache_filename);
if (time() - $cache_filetime <= $cache_lifetime) {
//** the cache is not expired
include($cache_filename);
} else {
//** the cache is expired
// load data from database
// ...
while ($dbo->nextRecord()) {
// $data[] = ...
}
// format the data as a php file
$data_cache = "while (list($key, $val) = each($ data)) {
$data_cache .= "$data['$key']=array('";
$data_cache .= "'NAME'=>"".qoute($val['NAME']). "","
$data_cache .= "'VALUE'=>"".qoute($val['VALUE'])."""
$data_cache .= ");rn";
}
$data_cache = "?>rn";
// save the data to the cache file
if ($fd = fopen($cache_filename,'w+')) {
fputs($fd,$data_cache);
fclose($fd) ;
}
}
return $data;
}
?>
Applicable situations:
1. The data is relatively stable, mainly for reading operations.
2. File operations are faster than database operations.
3. Complex data access, large data volume access, intensive data access, the system database load is extremely heavy.
4.Web/DB separation structure or multi-Web single DB structure.
Unconfirmed questions:
1. Will reading and writing files during concurrent access cause locking problems.
2. How is the performance when there are too many data files involved?
Extension ideas:
1. Generate JavaScript data definition code and call it on the client.
2. Haven’t thought of it yet...
Hope to discuss it together.
Caching
If you want to make your huge PHP application have better performance, using caching is also a good way. There are many caching solutions available, including: Zend Cache, APC, and Afterburner Cache.
All these products belong to "caching modules".When a request for a .php file first occurs, they save the PHP intermediate code in the web server's memory, and then respond to subsequent requests with the "compiled" version. This approach can really improve application performance because it reduces disk access to a minimum (the code has been read and parsed), and the code runs directly in memory, making the server respond to requests much faster. Of course, the caching module will also monitor changes in PHP source files and re-cache the page if necessary, thus preventing the user from getting pages that are still generated by outdated PHP code. Since caching modules can significantly reduce the load on the server and improve the response efficiency of PHP applications, they are very suitable for websites with heavy loads.
How to choose these caching products
Zend Cache is a commercial software from Zend Technologies, and Zend Technologies is the company mentioned earlier that provides us with the PHP engine and free Zend Optimizer. Zend Cache is indeed well-deserved! For large PHP pages, you can feel that the speed will increase after the first run, and the server will have more available resources. Unfortunately this product isn't free, but in some cases it can still be a steal.
Afterburner Cache is a free caching module from Bware Technologies. This product is currently in Beta version. Afterburner Cache looks similar to Zend Cache, but it doesn't improve performance as much as Zend Cache (yet), and it doesn't work with Zend Optimizer.
APC is the abbreviation of Alternative PHP Cache, which is another free caching module from Community Connect. The product is already stable enough for formal use, and it seems to improve the speed of responding to requests to a great extent.

Current page 1/3 123Next page

The above introduces the method of measuring the acceleration of the slider on the air cushion guide rail. How to increase the PHP speed on page 1/3, including the content of measuring the acceleration of the slider on the air cushion guide rail. I hope it will be helpful to friends who are interested in PHP tutorials.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template