Using pear to buffer PHP programs

Source: Internet
Author: User
Tags dsn pear php website semaphore
The PHP world of buffering is a hot topic, because the dynamic page generated by PHP, each user request needs to be recalculated, regardless of the request results are the same, and PHP will compile a script each time. This overload is certainly unbearable for a site with high traffic. Fortunately, Web results can be buffered without the need to rerun and compile scripts, and commercialized products like Zendcache or open source alternate PHP cache provide a way to compile PHP scripts into byte code and buffer them.
PEAR's buffer package provides a framework for buffering dynamic content, database queries, and PHP function calls.
Just as Perl has CPAN, TeX has ctan,php also has its own central repository, storing 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 go to the PHP website to download.

PEAR's buffer package contains an overall buffer class and several special subclasses. Buffer classes use container classes to store and manage buffered data.
The following are the containers currently contained in the PEAR buffer, along with their respective parameters:
FILE--The file container stores buffered data in the filesystem and is the fastest container.
Cache_dir-This is the directory where the container stores files.
Filename_prefix-The prefix of the buffered file, for example: "Cache_".
SHM--The SHM container puts the buffered data into shared memory, and the benchmark shows that the current implementation of the container is slower than the file container.
Shm_key-the key value used by shared memory.
Shm_perm-the right to use the shared memory data segment.
Shm_size-Allocates the size of shared memory.
Sem_key--The key value of the semaphore.
Sem_perm--The right of the semaphore.
DB--PEAR's database abstraction layer.
DSN-the DSN for the database connection. You can refer to PEAR's DB documentation.
Cache_table--The name of the table.
Phplib--The Phplib container uses the database abstraction layer to store buffers.
Db_class
Db_file
Db_path
Local_file
Local_path
EXT/DBX-PHP's database abstraction layer expands to use this container if the buffer is stored in a database.
Module
Host
Db
Username
Password
Cache_table
Persistent
The performance boost you get with PEAR Cache depends on the buffer container you choose, for example, it makes no sense to put the results of a database back into the database buffer.
The function buffer module of PEAR cache can buffer the result of any function or method, whether PHP's built-in function or user-defined function, he defaults to the file container, put the buffer data into a called
The Function_cache directory.

The constructor for the Cache_function class can have three optional parameters:

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.