search
HomeBackend DevelopmentPHP TutorialUsing PEAR to buffer PHP programs_PHP tutorial
Using PEAR to buffer PHP programs_PHP tutorialJul 13, 2016 pm 05:12 PM
pearphpworlddynamicyesPopularofprogrambufferusepage

Buffering is a hot topic in the PHP world, because the dynamic pages generated by PHP need to be recalculated every time the user requests it, regardless of whether the request result is the same. At the same time, PHP compiles the script every time. Such overload would certainly be unbearable for a website with high traffic. Fortunately, the results of the Web can be cached without the need to rerun and compile the script. Commercial products like ZendCache or the open source Alternate PHP Cache provide a way to compile PHP scripts into bytecode and cache them.
PEAR's buffering package provides a framework for buffering dynamic content, database queries, and PHP function calls.
Just like Perl has CPAN and TeX has CTAN, PHP also has its own central resource library to store 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.

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 included in the PEAR buffer, and their respective parameters:
file -- the file container stores buffered data in the file system and is the fastest container.
cache_dir -- This is the directory where the container stores files.
filename_prefix -- the prefix of the cache file, for example: "cache_".
shm -- The shm container puts buffered data into shared memory. Benchmark tests show that under the current implementation, this container is slower than the file container.
shm_key -- the key value used by shared memory.
shm_perm -- Permission to use the shared memory data segment.
shm_size -- The size of allocated shared memory.
sem_key -- The key value of the semaphore.
sem_perm -- semaphore permissions.
db -- PEAR's database abstraction layer.
dsn -- DSN of database connection. You can refer to PEAR’s DB documentation.
cache_table -- the name of the table.
phplib -- The phplib container uses a database abstraction layer to store buffers.
db_class
db_file
db_path
local_file
local_path
ext/dbx -- PHP's database abstraction layer extension. If you want to store buffers in the database, you can use this container.
module
host
db
username
password
cache_table
persistent
The performance improvement you get from using PEAR Cache depends on the buffer container you choose, for example, It is meaningless to store the database results in the database buffer again.
PEAR Cache's function buffer module can cache the results of any function or method, whether it is PHP's built-in function or a user-defined function. It uses a file container by default and puts the buffered data into a file called
function_cache directory.

The constructor of the Cache_Function class can have three optional parameters:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629330.htmlTechArticleBuffering is a hot topic in the PHP world, because the dynamic pages generated by PHP need to be refreshed every time the user requests Calculation, regardless of whether the result of the request is the same, at the same time, PHP will...
Statement
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
PHP将行格式化为 CSV 并写入文件指针PHP将行格式化为 CSV 并写入文件指针Mar 22, 2024 am 09:00 AM

这篇文章将为大家详细讲解有关PHP将行格式化为CSV并写入文件指针,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。将行格式化为CSV并写入文件指针步骤1:打开文件指针$file=fopen("path/to/file.csv","w");步骤2:将行转换为CSV字符串使用fputcsv()函数将行转换为CSV字符串。该函数接受以下参数:$file:文件指针$fields:作为数组的CSV字段$delimiter:字段分隔符(可选)$enclosure:字段引号(

php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.