Using PEAR to buffer PHP program _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags php database php website
Use PEAR to buffer PHP programs. Buffer is a hot topic in the PHP world, because every user request generated by PHP needs to be re-computed, regardless of whether the request results are the same, caching in the PHP world is a hot topic for PHP every time. because the dynamic page generated by PHP requires re-calculation for each user request, regardless of whether the request results are the same, PHP compiles the script once every time. This overload is certainly intolerable for a website with high traffic. Fortunately, Web results can be buffered without re-running or compiling scripts, commercial products such as ZendCache or open-source Alternate PHP Cache provide methods to compile PHP scripts into byte code and buffer them.
The PEAR buffer package provides a framework for caching dynamic content, database queries, and PHP function calls.
Just like Perl has CPAN, TeX has CTAN, and PHP also has its own central resource library, which stores classes, libraries, and modules. This library is called PEAR (PHP Extension and Add-On Repository ).
This article assumes that you have installed the PEAR environment. if not, you can download it from the PHP website.

The PEAR buffer package contains an overall buffer class and several special sub-classes. The buffer class uses the container class to store and manage the buffered data.
The following are the containers currently included in the PEAR buffer and their respective parameters:
The file-file container stores buffered data in the file system and is the fastest container.
Cache_dir -- this is the Directory of the container storage file.
Filename_prefix -- prefix of the buffer file, for example, "cache _".
The shm -- shm container puts the buffered data into the shared memory. the benchmark test shows that the current implementation of this container is slower than the file container.
Shm_key -- the key value used by the shared memory.
Shm_perm -- permission to use the data segment in the shared memory.
Shm_size -- size of shared memory allocated.
Sem_key -- the key value of the traffic signal.
Sem_perm -- specifies the traffic signal permission.
Db-PEAR database abstraction layer.
Dsn: the DSN of the database connection. See the pear db document.
Cache_table -- Name of the table.
Phplib -- phplib container uses database abstraction layer storage buffer.
Db_class
Db_file
Db_path
Local_file
Local_path
Ext/dbx -- PHP database abstraction layer extension. this container can be used if the buffer is saved to the database.
Module
Host
Db
Username
Password
Cache_table
Persistent
The performance improvement with PEAR Cache depends on the selected buffer container. for example, it is meaningless to store the database results in the database buffer again.
The function buffer module of PEAR Cache can buffer the results of any function or method. whether it is a PHP built-in function or a user-defined function, it uses a file container by default and puts the buffered data into
Function_cache directory.

The Cache_Function constructor can have three optional parameters:

Buffer is a hot topic in the http://www.bkjia.com/PHPjc/629330.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/629330.htmlTechArticlePHP world, because PHP generates dynamic pages, every user request needs to be re-computed, regardless of whether the request results are the same, at the same time, PHP every time will be...

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.