6

我已经在我的服务器中安装了 APC PHP。PHPinfo 正在显示它。但是刚问了一个问题,因为我有点困惑...

到达服务器的新 PHP 请求会自动开始使用 APC,还是需要修改 php 代码才能使用 APC?你能提供一些线索吗?

谢谢

4

3 回答 3

2

PHP 会自动使用它。您根本无需更改代码即可使用缓存加速器。

于 2012-12-20T02:01:33.533 回答
1

APC 正在自动运行。该模块运行您的代码并将其转换为字节码。当您再次调用脚本时,您的网络服务器不会再次运行脚本,而是执行字节码。

如果你有很多流量,它会节省很多性能。

第二个功能是您可以根据需要将值保存在 APC 的共享内存中。为此,您应该阅读文档。

http://php.net/manual/de/book.apc.php

于 2012-12-20T02:02:50.410 回答
0

如果 apc 存在,它将被使用。除非默认值为apc.enabledFalse,否则请在 phpinfo.xml 中查看。

如果启用的设置正常,则第一个 apc 使用将是操作码。存储 php 脚本的“编译”版本。现在,通过打开 apc 的几个设置(例如避免在每次文件访问时检查源代码修改),可以大大增强这种行为。

APC 中还有一个第二大功能,就是将其用作应用程序的持久性/缓存存储。但是这些东西需要在您的应用程序中使用特定的应用程序指令,就像您使用数据库一样。检查这些功能

要真正激活 APC优化,您应该查看所有 APC 设置。apc.shm_size并且apc.shm_segments对于检查 APC 内存大小的设置最有用,并且为所有虚拟主机共享。但是在这些基本设置之后,您应该检查虚拟主机/应用程序(您将在其中使用 php_value 指令)或全局 php.ini 中的一些内容,这是生产配置的摘录:

请注意,您应该了解每个激活的设置并阅读文档,否则您将在开发中浪费时间,因为您的源代码更改不会被 php 读取

# Activate apc
apc.enabled =1
# Optimisation of include/require_once calls
apc.include_once_override =1
# transform paths in absolute ones (no effect if apc.stat is not 0),
# files from stream wrappers (extended includes)
# won't be cached if this is activated as they cannot be used with php's realpath()
apc.canonicalize  =1  
# In production set it to 0, then file changes won't be observed before 
# apache is restarted,
# significant boost, else file time is stated at each access (needed at 1 in dev)
apc.stat =0
# avoid problems with rsync or svn not modifying mtime but only ctime
# so if you're in production set this to 0, like for the previous one 
apc.stat_ctime =0  

# deprecated option: apc.optimization not available anymore
# apc.optimization =0  

# inform apc on number of files of the application
apc.num_files_hint =2000

# inform apc on the number of cache variables
apc.user_entries_hint =100

# cache lifetime managmenent ----------------
# time (s) we can stay on the cache even when the cache is full -- Cache full count --
# that means Garbage Collector is never inactivating theses datas before this time is over
# >0 -> old data could stay in the cache while new data want's to come, if no data is deprecated
# 7200 -> entries older than 2 hours will be thrown to make some place
# 0 -> emptying full cache when full
apc.ttl =0
apc.user_ttl =0
# this one is the same but you should note this this prevent Garbage collecting 
# after each source change.
apc.gc_ttl =0

# What to cache ? ----------------------------
# could be used to prevent some caching on specific files
# but it's better to cache often used files, isn't it? at least in production
#apc.filters  ="-config.php-.ini"
# default to 1M, files bigger than that won't be cached
apc.max_file_size  ="5M"

# various things -------------------------------
# only one process caching a same file (beter than apc.slam_defense)
php_fla apc.write_lock  =1  
# prevents caching half written files (by cp for example) by waiting x seconds
# for new files caching. set it to 0 if using only rsync or mv
apc.file_update_protection  =2
# newest versions of APC only
# adding a lazy loading capabilities, so you can parse a lot of files
# and only used things are cached
#apc.lazy_functions =1
#apc.lazy_classes  =1
于 2012-12-20T08:59:21.180 回答