安装php_pcel_apc扩展

来源:互联网 发布:打开淘宝跳转到百度 编辑:程序博客网 时间:2024/06/09 17:46

Install

Phpize

./configure --with-php-config=/usr/bin/php/php-config

Make 

Make install

Configure and Use

默认的 APC 设定对于大多数安装已经没问题;

专业人员可以考虑调整以下参数。

APC有两个主要的配置选项。第一,多少内存将被分配给APC;第二,每次请求APC是否检查文件修改。 apc.shm_size 和apc.stat. 两个ini选项分别控制这些设置

[root@test develop]# cat /etc/php.d/apc.ini | grep -v '^;'

extension = apc.so

动态链接库方式载入扩展

apc.enabled=1

apc.enabled 可以设成 来禁用 APC.主要是用在当 APC 被静态编译入 PHP 时,因为没有其它方法来禁用了(编译为 DSO , 的时候,可以将php.ini中的extension 行注释掉)。 

apc.shm_segments=1

编译器缓存要分配的共享内存块的数目。如果 APC 用光了共享内存但是已经将 apc.shm_size 设为了系统所能允许的最大值,可以尝试增大此值

Want to avoid segmentation with apc.shm_segments?If your linux server limits the shared memory block size and you're forced to use apc.shm_segments instead, change the setting by using (here is 512M but change it as you like):

# sysctl -w kernel.shmmax=536870912

(but if you want the change to be permanent after a restart you would have to add the following line in /etc/sysctl.conf

kernel.shmmax=536870912)

and updating apc.ini

apc.shm_segments="1"

apc.shm_size="512" 

【译文】

如何避免用apc.shm_segments分割共享内存区?如果是由于您的linux服务器限制了共享内存块儿的大小,有可以采用shm_segments,或者更改配置

sysctl -w kernel.shmmax=536870912 

这里更改为512M,您可以根据自己的情况适当修改,若想重启后依然是修改后的值,请将命令写入 /etc/sysctl.conf

sysctl -w kernel.shmmax=536870912

Apc.ini中配置为

apc.shm_segments="1"

apc.shm_size="512" 

apc.shm_size=64

以 MB 为单位的每个共享内存块的大小。默认时,有些系统(包括大多数 BSD 变种)的共享内存块大小非常低。

apc.num_files_hint=1024

Web 服务器上的被包含或被请求的不同源文件的数目的大概估计。如果不确定则设为 或去掉此项;此设定主要用在有数千个源文件的站点。

apc.user_entries_hint=4096

apc.num_files_hint类似根据唯一用户数来存储缓存变量。 如果不能确定则设置为0或或去掉此项。 

apc.ttl=7200

缓存条目在缓冲区中允许逗留的秒数。表示永不超时。建议值为7200~86400 设为 意味着缓冲区有可能被旧的缓存条目填满,从而导致无法缓存新条目。 

apc.use_request_time=1

apc.user_ttl=7200

类似于apc.ttl,只是针对每个用户而言,建议值为7200~86400。 设为 意味着缓冲区有可能被旧的缓存条目填满,从而导致无法缓存新条目。 如果大于0APC将尝试删除过期条目。 

apc.gc_ttl=3600

缓存条目在垃圾回收表中能够存在的秒数。此值提供了一个安全措施,即在服务器进程在执行缓存的源文件时,如果该文件被修改则旧版本将不会被回收,直到达到此 TTL 为止。设为零将禁用此特性。 

apc.cache_by_default=1

默认为 on,但可以设为 off 并和加号开头的 apc.filters 一起用,则文件仅在匹配过滤器时被缓存。 

To automatically cache only PHP class files named "<class name>.class.php", add the following lines to php.ini.

apc.cache_by_default = "Off"

apc.filters = "+\.class\.php$"

Notes:

- The regexp is case /sensitive/, so if, say, your project contains filenames with mixed case, you'll need something like "+\.(class|CLASS)\.(php|PHP)$".  I've tried delimiting patterns and using the "i" modifier, but that doesn't seem to work.

- Setting cache_by_default to "On" and applying the positive filter will /not/ work.

If you have more complicated requirements and, like me, you're not familiar with POSIX Extended Regular Expressions (ERE) inparticular, you may find the following link useful.  http://www.regular-expressions.info/refflavors.html

【译文】

为了只缓存<class name>.class.php命名规则的文件,可以如下设置

Apc.cache_by_default = "Off"

Apc.filters = "+\.class\.php$"

注意:

正则表达式/sensitive/ ,(正则表达式大小写敏感),意味着如果您的项目中包含混写形式,您可能需要这样做"+\(class|CLASS)\.(php|PHP)$". 我曾经尝试用正则表达式修饰符"i",但是不能正常工作。

当默认缓存开启时apc.filters不工作。

如果你有更复杂的请求形式或者跟我一样不是很熟悉posix扩展形式的正则表达式,你可以访问"http://www.regular-expressions.info/refflavors.html"得到帮助。

Apc.filters

一个以逗号分隔的 POSIX 扩展正则表达式的列表。如果任一个模式匹配源文件名,则该文件不被缓存。注意用来匹配的文件名是传递给 include/require 的文件名,而不是绝对路径。如果正则表达式的第一个字符是+ t则意味着任何匹配表达式的文件会被缓存,如果第一个字符是 - 则任何匹配项都不会被缓存。 -是默认值,可以省略掉。 

apc.mmap_file_mask=/tmp/apc.XXXXXX

如果使用 --enable-mmap(默认启用)APC编译了MMAP支持, 这里的值就是传递给mmap模块的mktemp风格的文件掩码(建议值为/tmp/apc.XXXXXX")。 该掩码用于决定内存映射区域是否要被file-backed或者shared memory backed 对于直接的file-backed内存映射,要设置成"/tmp/apc.XXXXXX"的样子(恰好6X)。 要使用POSIX风格的shm_open/mmap就需要设置成"/apc.shm.XXXXXX"的样子。 你还可以设为"/dev/zero"来为匿名映射的内存使用内核的"/dev/zero"接口。 不定义此指令则表示强制使用匿名映射。 

apc.file_update_protection=2

当你在一个运行中的服务器上修改文件时,你应当执行原子操作。 也就是先写进一个临时文件,然后将该文件重命名(mv)到最终的名字。 文本编辑器以及 cptar 等程序却并不是这样操作的,从而导致有可能缓冲了残缺的文件。 默认值 表示在访问文件时如果发现修改时间距离访问时间小于 秒则不做缓冲。 那个不幸的访问者可能得到残缺的内容,但是这种坏影响却不会通过缓存扩大化。 如果你能确保所有的更新操作都是原子操作,那么可以用 关闭此特性。 如果你的系统由于大量的IO操作导致更新缓慢,你就需要增大此值。 

apc.enable_cli=1

是否为CLI版本启用APC功能,仅用于测试和调试目的才打开此选项。 在正常情况下不是理想的创建、 填充和销毁 CLI 的每个请求上的 APC 缓存,但各种测试方案很有用,能够轻松地使 CLI 版本的 PHP APC 

apc.max_file_size=1M

当大于此值时不被缓存

If you are getting 0kb out of 0kb for your upload progress with large files, make sure that upload_max_filesize and post_max_size are larger than the file you are uploading. As far as I can tell, apc.max_file_size does not affect it.

【译文】

此选项不影响最大上传的文件大小限制

apc.stat=1

是否启用脚本更新检查。 改变这个指令值要非常小心。 默认值 On 表示APC在每次请求脚本时都检查脚本是否被更新, 如果被更新则自动重新编译和缓存编译后的内容。但这样做对性能有不利影响。 如果设为 Off 则表示不进行检查,从而使性能得到大幅提高。 但是为了使更新的内容生效,你必须重启Web服务器(译者注:如果采用cgi/fcgi类似的,需重启cgi/fcgi进程)。 生产服务器上脚本文件很少更改可以通过禁用本选项获得显著的性能提升。

这个指令对于include/require的文件同样有效。但是需要注意的是, 如果你使用的是相对路径,APC就必须在每一次include/require时都进行检查以定位文件。 而使用绝对路径则可以跳过检查,所以鼓励你使用绝对路径进行include/require操作。

apc.stat is an extremely important setting for a production server, especially if many files are accessed on every request, which is quite normal on complicated web applications.

Always aspire to use:

apc.stat="0"

so that APC does not try to check that each and every file exists on every request you make. It also means you can update files on your server without crashing incoming requests on that time fragment. Whenever you wish to force APC to re-read all the files, simply clear the cache or restart your server.

【译文】

Apc.stat在生产机上是非常重要的配置参数,尤其对于复杂的web应用。通常关闭apc.stat=0,这样apc不会每次请求都检查脚本修改时间,这意味着你可以修改服务器上的文件,而不会冲掉缓冲区的opcode,此刻请求道德还是缓冲区内的内容,当以确定更新正确完成时,可以通过重启web server或者apc_clear_cache(),来清空缓存

apc.stat_ctime=0

验证ctime(创建时间)可以避免SVN或者rsync带来的问题,确保自上次统计inode没有改变。APC通常只检查mtime(修改时间)

apc.canonicalize=0

apc.write_lock=1

在繁忙的服务器上,Web服务器第一次被启动,或者很多文件在同一时间被修改,APC可能会多次编译同一个文件,写锁保证只有一个进程将尝试编译并缓存未缓存的脚本。其他进程试图使用该脚本将不使用opcode缓存,而不是锁定和等待缓存生成。

apc.report_autofilter=0

是否记录所有由于early/late binding原因而自动未被缓存的脚本

apc.rfc1867=0

RFC1867 File Upload Progress hook handler is only available if APC was compiled against PHP 5.2.0 or later. When enabled, any file uploads which includes a field called APC_UPLOAD_PROGRESS before the file field in an upload form will cause APC to automatically create an upload_key user cache entry where key is the value of the APC_UPLOAD_PROGRESS form entry.

Note that the hidden field specified by APC_UPLOAD_PROGRESS must come before the file field, otherwise the upload progress will not work correctly.

Note that the file upload tracking is not threadsafe at this point, so new uploads that happen while a previous one is still going will disable the tracking for the previous. 

apc.rfc1867_prefix =upload_

用于上传文件的缓冲项条目名称前缀 

apc.rfc1867_name=APC_UPLOAD_PROGRESS

用于上传文件的缓冲项条目名称前缀 

neorush at gmail dot com 26-Aug-2009 10:16

apc_fetch always returned false.  Turns out that "apc.rfc1867" was set to "0".  I added this line to my php.ini:

apc.rfc1867 = 1

but it could have certainly been changed with ini_set().  That took me way to long to figure out.

bishop 26-Feb-2009 03:22

The apc.rfc1867 example code above is a little fast and loose for those running in environments where APC RFC1867 may or may not be available.  This is a little more expressive:

<?php

// if we have PHP and APC

$havePHP = (1 === version_compare(PHP_VERSION, '5.2.0') ? true : false);

$haveAPC = (extension_loaded('apc') && 1 === version_compare(phpversion('apc'), '3.0.13') ? true : false);

if ($havePHP && $haveAPC) {

    // if APC and upload tracking is enabled

    if (ini_get('apc.enabled') && ini_get('apc.rfc1867')) {

        // get the stats

        $key = ini_get('apc.rfc1867_prefix') . $_REQUEST['apcid'];

        $stats = apc_fetch($key);

    }

}

?>

lamperz at gmail dot com 31-Oct-2008 05:52

I'm trying to get upload progress with apc_fetch.

I founded apc_fetch always return false till the upload completed.After fews hours debug, I finally notice that my APC_UPLOAD_PROGRESS was set after the file form.

SO, You should write your form like this

<input type="hidden" id="file_id" name="APC_UPLOAD_PROGRESS" value="blablabla"/>

<input type="file" id="select_file" name="file" value="upload" onchange="parent.test();"/>

the hidden field with name="APC_UPLOAD_PROGRESS" SHOULD be ALWAYS BEFORE input type="file"

apc.rfc1867_freq=0

用户上传文件缓存项的更新频率。 取值可以是总文件大小的百分比,或者以 "k", "m", or "g" kilobytes, megabytes, or gigabytes 结尾的绝对尺寸 (大小写不敏感). 0 表示尽可能快的更新,不过这样可能会导致上传速度下降。 

apc.rfc1867_ttl=3600

apc.include_once_override=0

优化include_once()require_once()函数以避免执行额外的系统调用,这个推荐关闭,防止重复的包含可以通过良好的WEB脚本的存放结构避免

apc.lazy_classes=00

启用类延迟加载 

apc.lazy_functions=0

启用函数延迟加载 

apc.coredump_unmap=0

启用APC的信号句柄,例如SIGSEGV信号,当信号写入核心文件。当这些信号被接收,APC将试图取消映射的共享内存段,从核心文件中排除它。此设置可以提高系统的稳定性,当接受到致命的信号或者采用APC的大型共享内存段配置方式。 

此功能是潜在的危险。如果发生致命错误取消映射一个共享内存段致命的信号句柄, 可能会导致不可预知的结果。

 虽然有些内核可能会提供了便利,忽略各类共享内存时生成核心转储文件,这些实现可能也忽略了重要的共享内存段,比如 Apache scoreboard。 

apc.file_md5=0

记录文件的md5

apc.preload_path

1,使用Spinlocks锁机制,能够达到最佳性能。

2,APC提供了apc.php,用于监控与管理APC缓存。不要忘记修改管理员名和密码

3,APC默认通过mmap匿名映射创建共享内存,缓存对象都存放在这块”大型”的内存空间。由APC自行管理该共享内存

4,我们需要通过统计调整apc.shm_sizeapc.num_files_hintsapc.user_entries_hint的值。直到最佳

5,好吧,我承认apc.stat = 0 可以获得更佳的性能。要我做什么都可以接受.

6,PHP预定义常量,可以使用apc_define_constants()函数。不过据APC开发者介绍说pecl hidef性能更佳,抛异define吧,它是低效的。

7,函数apc_store(),对于系统设置等PHP变量,生命周期是整个应用(httpd守护进程直到httpd守护进程关闭),使用APCMemcached会更好。必竟不要经过网络传输协议tcp

8,APC不适于通过函数apc_store()缓存频繁变更的用户数据,会出现一些奇异现象。