search
HomeBackend DevelopmentPHP Tutorial 【集锦】PHP扩展【xhprof,eaccelerator】

【汇总】PHP扩展【xhprof,eaccelerator】

环境

1.PHP 5.3.8,使用fastcgi方式安装,安装目录/usr/local/php

2.CentOS 5.5

?

xhprof

生成xhprof.so

#unzip -o xhprof-0.9.2.zip
#cd xhprof-0.9.2
#cd xhprof-0.9.2/xhprof-0.9.2/extension/
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config
#make
#make install

将生成的xhprof.so放入php的extension_dir下,配置php.ini后,重启php

// 放入php的extension_dir目录下
...

// 配置php.ini
#vi /usr/local/php/lib/php.ini
---
[xhprof]
extension="xhprof.so";
xhprof.output_dir="/var/cache/xhprof"
---

// 重启php
#pkill -o php-fpm
#/usr/local/php/sbin/php-fpm

// 查看phpinfo,检查xhprof是否安装成功
...?

将xhprof_lib,xhprof_html移动到网站目录下

...

写php代码,使用xhprof模块

<?php

// 开启xhprof
if(function_exists('xhprof_enable')) { 
    xhprof_enable(); 
}

// 你的php代码

// 生成报告
if(function_exists('xhprof_disable')) {
    $xhprof_data = xhprof_disable();
    include_once "xhprof_lib/utils/xhprof_lib.php";
    include_once "xhprof_lib/utils/xhprof_runs.php";

    $xhprof_runs = new XHProfRuns_Default();
    $identifier = rand(0,9999);
    $run_id = $xhprof_runs->save_run($xhprof_data, $identifier);

    echo "<a target=\"_blank\" href=\"xhprof_html/index.php?run={$run_id}&source={$identifier}\">view xhprof </a>";
}
?

eaccelerator

生成eaccelerator.so

#tar -zxvf eaccelerator-0.9.6.1.zip
#cd eaccelerator-0.9.6.1
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config
#make
#make install
?

将生成的eaccelerator.so放入php的extension_dir下,配置php.ini后,重启php

// 放入php的extension_dir目录下  
...  
  
// 配置php.ini  
#vi /usr/local/php/lib/php.ini  
---  
[eaccelerator]
extension="eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.keys = "disk_only"
eaccelerator.sessions = "disk_only"
eaccelerator.content = "disk_only"
---  
  
// 重启php  
#pkill -o php-fpm
#/usr/local/php/sbin/php-fpm
  
// 查看phpinfo,检查eaccelerator是否安装成功
...

?

eaccelerator详细配置说明

此为转载,特此说明,转载地址:http://www.21andy.com/blog/20100207/1646.html

---

eaccelerator.shm_size="32"
eAccelerator 可以使用的共享内存的数量 (以兆为单位) . "0" 是指操作系统的默认值. 默认值是 "0".可根据服务器的实际情况来调整,16,32,64,128都是可以的。

eaccelerator.cache_dir="/home/php/tmp"
这个目录是给磁盘缓存使用. eAccelerator 在这里储存预先编译好的代码, 进程数据, 内容以及用户的自定义内容. 同样的数据也能被储存在共享内存中 (这样可以提高访问速度). 默认的设置是 "/tmp/eaccelerator".

eaccelerator.enable="1"
开启或关闭 eAccelerator。"1" 为开启,"0" 为关闭。默认值为 "1"。

eaccelerator.optimizer="1"
启或关闭内部优化器,可以提升代码执行速度。"1" 为开启,"0" 为关闭。默认值为 "1"。

eaccelerator.check_mtime="1"
打开或者关闭 PHP 的文件修改检查. "1" 是指打开, "0" 是指关闭. 如果您在修改以后重新编译 PHP 的文件,那么您应当设置为 "1". 默认值是 "1".

eaccelerator.debug="0"
开启或关闭调试日志记录。"1" 为开启,"0" 为关闭。默认值为 "0"。会将缓存命中得记录写入日志。

eaccelerator.filter=""
判断哪些 PHP 文件必须缓存。您可以指定缓存和不缓存的文件类型(如 "*.php *.phtml"等)
如果参数以 "!" 开头,则匹配这些参数的文件被忽略缓存。默认值为 "",即,所有 PHP 文件都将被缓存。

eaccelerator.shm_max="0"
当使用 " eaccelerator_put() " 函数时禁止其向共享内存中存储过大的文件。该参数指定允许存储的最大值,单位:字节 (10240, 10K, 1M)。"0" 为不限制。默认值为 "0"。

eaccelerator.shm_ttl="0"
当 eAccelerator 获取新脚本的共享内存大小失败时,它将从共享内存中删除所有在最后 "shm_ttl" 秒内没有存取的脚本缓存。默认值为 "0",即:不从共享内春中删除任何缓存文件。

eaccelerator.shm_prune_period="0"
当 eAccelerator 获取新脚本的共享内存大小失败时,他将试图从共享内存中删除早于"shm_prune_period" 秒的缓存脚本。默认值为 "0",即:不从共享内春中删除任何缓存文件。

eaccelerator.shm_only="0"
允许或禁止将已编译脚本缓存在磁盘上。该选项对 session 数据和内容缓存无效。默认值为 "0",即:使用磁盘和共享内存进行缓存。

eaccelerator.compress="1"
允许或禁止压缩内容缓存。默认值为 "1",即:允许压缩。

eaccelerator.compress_level="9"
指定内容缓存的压缩等级。默认值为 "9",为最高等级。

eaccelerator.keys = "disk_only"
eaccelerator.session = "disk_only"
eaccelerator.content = "disk_only"
设置内容缓存的存放的地方,可以设置为:
shm_and_disk 在共享缓存和硬盘(默认值)
shm 默认存在共享内存,如果共享内存已满或大小超过 "eaccelerator.shm_max" 的值,就存到硬盘
shm_only 只存放在共享内存
disk_only 只存放在硬盘
none 不缓存数据

eaccelerator.allowed_admin_path = "/var/www/html/21andy.com/eaccelerator"
这是控制面板的地址
安装包里有个control.php,你把它复制到网站的任意目录,可以用它查看和管理,这个必须指定,否则查看缓存内容的时候会出错

---

?

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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools