设为首页 收藏本站
查看: 3553|回复: 0

LNMP nginx1.4.6+php5.5.11+mysql5.6.17+mecache+opcache编译安装+opcache参数详解+opcache可视化

[复制链接]

尚未签到

发表于 2015-11-16 13:47:20 | 显示全部楼层 |阅读模式
可能要用到的软件:

libiconv-1.13.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
mhash-0.9.9.9.tar.gz
memcache-2.2.5.tgz
PDO_MYSQL-1.0.2.tgz
imagick-3.1.2.tgz
pcre-8.21.tar.gz
mysql-5.6.17.tar.gz
ImageMagick.tar.gz
php-5.4.21.tar.gz
nginx-1.4.6.tar.gz

系统安装需求:
centos 6.4 *86_64  mini安装

1 安装解决依赖关系(摘取天上星 奉献):
yum install -y wget gcc gcc-c++ autoconf libjpeg libjpeg-devel perl perl* perl-CPAN libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers png jpeg autoconf gcc cmake make gcc-c++ gcc ladp ldap* ncurses ncurses-devel zlib zlib-devel zlib-static pcre pcre-devel pcre-static openssl openssl-devel perl libtoolt openldap-devel libxml2-devel ntpdate cmake gd* gd2 ImageMagick-devel jpeg jpeg* pcre-dev* fontconfig libpng libxml2 zip unzip gzip
如果编译时遇到类似如下perl-xxx错误
Error: perl-JSON-PP conflicts with perl-JSON-2.15-5.el6.noarch Error: Package: perl-Image-SubImageFind-0.03-1.el6.x86_64 (epel)            Requires: libMagick++.so.2()(64bit) Error: Package: perl-Image-SubImageFind-0.03-1.el6.x86_64 (epel)
You could try using --skip-broken to work around the problem  You could try running: rpm -Va --nofiles --nodigest
从yum install安装中去掉 perl* 重新yum install即可


2 下载所有使用到的软件:
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.13.tar.gz
wget http://lcmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz
wget http://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://vps.googlecode.com/files/PDO_MYSQL-1.0.2.tgz
wget http://pecl.php.net/get/imagick-3.1.2.tgz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
wget http://mynginx.googlecode.com/files/ImageMagick.tar.gz
wget https://lnamp-web-server.googlecode.com/files/eaccelerator-eaccelerator-42067ac.tar.gz

  NGINX1.4.6: http://nginx.org/download/nginx-1.4.6.tar.gz
  MYSQL5.6.17   http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
  PHP5.5.11     http://us1.php.net/get/php-5.5.11.tar.gz/from/this/mirror
  先前分别在两台机器上编译过两次不同MYSQL版本:MYSQL5.6.12和MYSQL5.6.17 编译命令都是如下:
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data       \
-DSYSCONFDIR=/etc              \
-DWITH_MYISAM_STORAGE_ENGINE=1    \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1                    \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock      \
-DMYSQL_TCP_PORT=3306                  \
-DENABLED_LOCAL_INFILE=1            \
-DWITH_PARTITION_STORAGE_ENGINE=1  \
-DEXTRA_CHARSETS=all                  \
-DDEFAULT_CHARSET=utf8              \
-DDEFAULT_COLLATION=utf8_general_ci

  完成后,继续下面的操作

  • cd /usr/local/mysql  
  • chown -R mysql:mysql . (为了安全安装完成后请修改权限给root用户)
  • scripts/mysql_install_db --user=mysql (先进行这一步再做如下权限的修改)
  • chown -R root:mysql .  (将权限设置给root用户,并设置给mysql组, 取消其他用户的读写执行权限,仅留给mysql "rx"读执行权限,其他用户无任何权限)
  • chown -R mysql:mysql ./data   (给数据库存放目录设置成mysql用户mysql组,并赋予chmod -R ug+rwx  读写执行权限,其他用户权限一律删除仅给mysql用户权限)
  下面的命令是可选的,将mysql的配置文件拷贝到/etc

  • cp support-files/my-medium.cnf /etc/my.cnf  (原始老版本是此操作,5.6.12版本的是如下文件地址)
  • cp support-files/my-default.cnf  /etc/my.cnf  (并给/etc/my.cnf +x权限 同时删除 其他用户的写权限,仅仅留给root 和工作组 rx权限,其他一律删除连rx权限都删除)
#修改my.cnf配置
    vim /etc/my.cnf
    #[mysqld] 添加:
    datadir=/data/mysql
    default-storage-engine=MyISAM  启动mysql:
[c-sharp] view plaincopy

  • bin/mysqld_safe --user=mysql &  
  • #启动mysql,看是否成功  
  • netstat -tnl|grep 3306  
[c-sharp] view plaincopy

  • bin/mysqld_safe --user=mysql &  
  • #启动mysql,看是否成功  
  • netstat -tnl|grep 3306  
  上面是一种启动mysql的方法,还有一种简单的方便,如下:
[c-sharp] view plaincopy

  • #将mysql的启动服务添加到系统服务中  
  • cp support-files/mysql.server /etc/init.d/mysql  
  • #现在可以使用下面的命令启动mysql  
  • service mysql start  
  • #停止mysql服务  
  • service mysql stop  
  • #重启mysql服务  
  • service mysql restart  
  将mysql服务添加到开机启动项,让mysql服务开机启动
[c-sharp] view plaincopy

  • chkconfig --add mysql  修改默认root账户密码,默认密码为空
      修改密码 cd 切换到mysql所在目录

      cd /usr/local/mysql

      #./bin/mysqladmin -u root password

      回车在接下来的提示中设置新密码即可。。
      #启动MySQL
        /usr/local/mysql/bin/mysqld_safe –defaults-file=/etc/my.cnf &
        #或者
        /etc/init.d/mysql start (service mysql start)
        #测试MySQL是否启动
        # 1)查看是否有进程mysql
        ps -ef | grep mysql
        # 2)查看端口是否运行
        netstat -tnl | grep 3306
        # 3)读取mysql版本信息
        mysqladmin version


PHP5.4.8常用编译命令
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \  #此行仅在apache+php下使用,nginx+php时请去掉
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-iconv-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-session \
--with-gettext \
--enable-pdo \
--with-pdo-mysql \
--enable-shared \
--enable-ftp \
--enable-exif \
--with-pear
php5.5之后新增下面可选命令
--enable-opcache \
线上服务器可以加入以下命令关闭调试模式:
--disable-debug \
php5.5.11后无法识别的废旧编译选项(如果提示WRING警告无法识别--with-curlwrappers无视即可):
--with-curlwrappers
使用NGINX处理请去掉下面一行,下面一行仅在APACHE下使用
--with-apxs2=/usr/local/apache2/bin/apxs \
使用NGINX可以加入下面两行指定FPM运行账户权限:
--with-fpm-user=www \
--with-fpm-group=www \

  PHP编译选项说明
""" 安装路径 """
--prefix=/usr/local/php \
""" php.ini 配置文件路径 """
--with-config-file-path=/etc \
""" 优化选项 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """
--enable-opcache \
""" FPM """
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
""" MySQL """
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
""" 国际化与字符编码支持 """
--with-gettext \
--enable-mbstring \
--with-iconv \
""" 加密扩展 """
--with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """
--enable-bcmath \
""" Web 服务,依赖 libxml """
--enable-soap \
--with-libxml-dir \
""" 进程控制 """
--enable-pcntl \
--enable-shmop \
--enable-sysvsem \
""" socket & curl """
--enable-sockets \
--with-curl \
""" 压缩与归档 """
--with-zlib \
--enable-zip \
--with-bz2 \
""" GNU Readline 命令行快捷键绑定 """
--with-readline \
""" 禁用 SQLite 支持扩展 """
--without-sqlite3 \
--without-pdo-sqlite \
""" 更多 PHP 扩展与应用库 """
--with-pear
  在Linux下安装PHP,源代码方式安装,总需要配置很多参数。这里列出常用配置参数,并详细用中文解释说明了。给大家一些参考
  编译PHP的时候慎用 –with-curlwrappers参数

  ./configure
--prefix=/usr/local/PHP                                   php 安装目录
--with-apxs2=/usr/local/apache/bin/apxs     表示使用apache2.0以上版本,apxs表示使用的apache1.0版本
--with-config-file-path=/usr/local/PHP/etc               指定php.ini位置
--with-MySQL=/usr/local/mysql                        mysql安装目录,对mysql的支持
--with-MySQLi=/usr/local/mysql/bin/mysql_config            mysqli文件目录,优化支持
--enable-safe-mode                              打开安全模式
--enable-ftp                                 打开ftp的支持
--enable-zip                                 打开对zip的支持
--with-bz2                                    打开对bz2文件的支持                       
--with-jpeg-dir                                 打开对jpeg图片的支持
--with-png-dir                                 打开对png图片的支持
--with-freetype-dir                              打开对freetype字体库的支持
--without-iconv                                 关闭iconv函数,种字符集间的转换
--with-libXML-dir                                 打开libxml2库的支持
--with-XMLrpc                                 打开xml-rpc的c语言
--with-zlib-dir                                 打开zlib库的支持
--with-gd                                    打开gd库的支持
--enable-gd-native-ttf                           支持TrueType字符串函数库
--with-curl                                    打开curl浏览工具的支持
--with-curlwrappers                              运用curl工具打开url流
--with-ttf                                    打开freetype1.*的支持,可以不加了
--with-xsl                                     打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件
--with-gettext                                 打开gnu 的gettext 支持,编码库用到
--with-pear                      打开pear命令的支持,PHP扩展用的
--enable-calendar                  打开日历扩展功能
--enable-mbstring                  多字节,字符串的支持
--enable-bcmath                  打开图片大小调整,用到zabbix监控的时候用到了这个模块
--enable-sockets                  打开 sockets 支持
--enable-exif                      图片的元数据支持
--enable-magic-quotes               魔术引用的支持
--disable-rpath                     关闭额外的运行库文件
--disable-debug                  关闭调试模式
--with-mime-magic=/usr/share/file/magic.mime      魔术头文件位置
  --enable-opcache //PHP5.5X+新增代码加速功能

CGI方式安装才用的参数
--enable-fpm                     打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序
--enable-fastCGI                  支持fastcgi方式启动PHP
--enable-force-CGI-redirect             同上 ,帮助里没有解释
--with-ncurses                     支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库
--enable-pcntl                     freeTDS需要用到的,可能是链接mssql 才用到

mhash和mcrypt算法的扩展
--with-mcrypt                     算法
--with-mhash                     算法

--with-gmp
--enable-inline-optimization
--with-openssl                     openssl的支持,加密传输时用到的
--enable-dbase
--with-pcre-dir=/usr/local/bin/pcre-config      perl的正则库案安装位置
--disable-dmalloc
--with-gdbm                     dba的gdbm支持
--enable-sigchild
--enable-sysvsem
--enable-sysvshm
--enable-zend-multibyte               支持zend的多字节
--enable-mbregex
--enable-wddx
--enable-shmop
--enable-soap

  

  准备PHP的配置文件
12# cd /home/down/php-5.5.11# cp php.ini-production /usr/local/php/etc/php.ini  准备php_fpm的配置文件
1234# cd /usr/local/php/etc/# cp php-fpm.conf.defaultphp-fpm.conf# vim php-fpm.conf  修改php-fpm.conf配置文件内容去掉如下前面的分号,并根据实际硬件配置进行更改
  这里仅做简单配置,下面会有PHP-FPM的详细的优化配置讲解

  
pid = run/php-fpm.pid
error_log = log/php-fpm.log
listen = 127.0.0.1:9000
pm.max_children = 40  
pm.start_servers = 12
pm.min_spare_servers = 4  
pm.max_spare_servers = 20  
pm.max_requests = 1000  


  使用php-fpm启动php需要注意的是启动配置文件需要给用户组+rx权限尤其要添加到服务器项+x权限,否则会因没有可执行权限而产生的异常错误

  Php-fpm代码

  php5.5X+版本提供了php-fpm的管理工具,可以很方便的start,stop,restart
  Php-fpm代码  

  •   // 个人习惯把php相关命令丢在这  
  •   #cd /usr/local/php/sbin/  
  •   
  •   // 在安装文件中复制该文件  
  •   #cp /home/down/php-5.5.11/sapi/fpm/init.d.php-fpm  ./  
  •   #chmod 755 init.d.php-fpm  
  •   
  •   // start | stop | restart  
  •   #./init.d.php-fpm start  

  另一种PHP-FPM启动方式

  测试php/php-fpm是否安装成功:
#测试php-fpm配置(实际路径根据自己PHP安装路径自行替换)/usr/local/php/sbin/php-fpm-t/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini -y/usr/local/php/etc/php-fpm.conf -t
出现类似如下提示证明测试通过,PHP/php-fpm安装成功
[18-Apr-2014 23:20:15] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful  (一点小插曲:第一次测试时启动时出现如下错误,vim /usr/local/php/etc/php-fpm.conf 打开找到第52行发现52行的修改注释忘记加注释符号分号“;”了,OK搞定

  Starting php-fpm [18-Apr-2014 23:09:15] ERROR: [/usr/local/php/etc/php-fpm.conf:52] value is NULL for a ZEND_INI_PARSER_ENTRY
[18-Apr-2014 23:09:15] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[18-Apr-2014 23:09:15] ERROR: FPM initialization failed)

#启动php-fpm/usr/local/php/sbin/php-fpm/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini -y/usr/local/php/etc/php-fpm.conf #关闭php-fpmkill -INT `cat /usr/local/php/var/run/php-fpm.pid` #重启php-fpmkill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
  php-fpm提供Sysv init脚本,并将其添加至服务列表 致使开机自动启动

123456# cd/home/down/php-5.5.11# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm# cp sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm# chmod +x /etc/init.d/php-fpm# chkconfig --add php-fpm# chkconfig php-fpm on
  完成如上操作即可在命令行使用service php-fpm start | stop | restart 进行 启动|停止|重启操作php-fpm了

php-fpm.conf重要参数详解
pid = run/php-fpm.pid#pid设置,默认在安装目录中的var/run/php-fpm.pid,建议开启 error_log = log/php-fpm.log#错误日志,默认在安装目录中的var/log/php-fpm.log log_level = notice#错误级别. 可用级别为: alert(必须立即处理), error(错误情况), warning(警告情况), notice(一般重要信息), debug(调试信息). 默认: notice. emergency_restart_threshold = 60emergency_restart_interval = 60s#表示在emergency_restart_interval所设值内出现SIGSEGV或者SIGBUS错误的php-cgi进程数如果超过 emergency_restart_threshold个,php-fpm就会优雅重启。这两个选项一般保持默认值。 process_control_timeout = 0#设置子进程接受主进程复用信号的超时时间. 可用单位: s(秒), m(分), h(小时), 或者 d(天) 默认单位: s(秒). 默认值: 0. daemonize = yes#后台执行fpm,默认值为yes,如果为了调试可以改为no。在FPM中,可以使用不同的设置来运行多个进程池。 这些设置可以针对每个进程池单独设置。 listen = 127.0.0.1:9000#fpm监听端口,即nginx中php处理的地址,一般默认值即可。可用格式为: 'ip:port', 'port', '/path/to/unix/socket'. 每个进程池都需要设置. listen.backlog = -1#backlog数,-1表示无限制,由操作系统决定,此行注释掉就行。backlog含义参考:http://www.3gyou.cc/?p=41 listen.allowed_clients = 127.0.0.1#允许访问FastCGI进程的IP,设置any为不限制IP,如果要设置其他主机的nginx也能访问这台FPM进程,listen处要设置成本地可被访问的IP。默认值是any。每个地址是用逗号分隔. 如果没有设置或者为空,则允许任何服务器请求连接 listen.owner = wwwlisten.group = wwwlisten.mode = 0666#unix socket设置选项,如果使用tcp方式访问,这里注释即可。 user = wwwgroup = www#启动进程的帐户和组 pm = dynamic #对于专用服务器,pm可以设置为static。#如何控制子进程,选项有static和dynamic。如果选择static,则由pm.max_children指定固定的子进程数。如果选择dynamic,则由下开参数决定:pm.max_children #,子进程最大数pm.start_servers#,启动时的进程数pm.min_spare_servers#,保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程pm.max_spare_servers#,保证空闲进程数最大值,如果空闲进程大于此值,此进行清理 pm.max_requests = 1000#设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 '0' 则一直接受请求. 等同于 PHP_FCGI_MAX_REQUESTS 环境变量. 默认值: 0. pm.status_path =/status#FPM状态页面的网址. 如果没有设置, 则无法访问状态页面. 默认值: none. munin监控会使用到 ping.path =/ping#FPM监控页面的ping网址. 如果没有设置, 则无法访问ping页面. 该页面用于外部检测FPM是否存活并且可以响应请求. 请注意必须以斜线开头 (/)。 ping.response = pong#用于定义ping请求的返回相应. 返回为 HTTP 200 的 text/plain 格式文本. 默认值: pong. request_terminate_timeout = 0#设置单个请求的超时中止时间. 该选项可能会对php.ini设置中的'max_execution_time'因为某些特殊原因没有中止运行的脚本有用. 设置为 '0' 表示 'Off'.当经常出现502错误时可以尝试更改此选项。 request_slowlog_timeout = 10s#当一个请求该设置的超时时间后,就会将对应的PHP调用堆栈信息完整写入到慢日志中. 设置为 '0' 表示 'Off' slowlog = log/$pool.log.slow#慢请求的记录日志,配合request_slowlog_timeout使用 rlimit_files = 1024#设置文件打开描述符的rlimit限制. 默认值: 系统定义值默认可打开句柄是1024,可使用 ulimit -n查看,ulimit -n 2048修改。 rlimit_core = 0#设置核心rlimit最大限制值. 可用值: 'unlimited' 、0或者正整数. 默认值: 系统定义值. chroot =#启动时的Chroot目录. 所定义的目录需要是绝对路径. 如果没有设置, 则chroot不被使用. chdir =#设置启动目录,启动时会自动Chdir到该目录. 所定义的目录需要是绝对路径. 默认值: 当前目录,或者/目录(chroot时) catch_workers_output =yes#重定向运行过程中的stdout和stderr到主要的错误日志文件中. 如果没有设置, stdout 和 stderr 将会根据FastCGI的规则被重定向到 /dev/null . 默认值: 空.PHP-FPM常见错误及解决办法整理
  如果file_get_contents请求的远程资源如果反应过慢,file_get_contents就会一直卡在那里不会超时。我们知道php.ini 里面max_execution_time 可以设置 PHP 脚本的最大执行时间,但是,在 php-cgi(php-fpm) 中,该参数不会起效。真正能够控制 PHP 脚本最大执行时间的是 php-fpm.conf 配置文件中的request_terminate_timeout参数。
  request_terminate_timeout默认值为 0 秒,也就是说,PHP 脚本会一直执行下去。这样,当所有的 php-cgi 进程都卡在 file_get_contents() 函数时,这台 Nginx+PHP 的 WebServer 已经无法再处理新的 PHP 请求了,Nginx 将给用户返回“502 Bad Gateway”。修改该参数,设置一个 PHP 脚本最大执行时间是必要的,但是,治标不治本。例如改成 30s,如果发生 file_get_contents() 获取网页内容较慢的情况,这就意味着 150 个 php-cgi 进程,每秒钟只能处理 5 个请求,WebServer 同样很难避免”502 Bad Gateway”。解决办法是request_terminate_timeout设置为10s或者一个合理的值,或者给file_get_contents加一个超时参数。
1234567 $ctx = stream_context_create(array(    'http'=>array(        'timeout'=> 10   //设置一个超时时间,单位为秒    ) ));  file_get_contents($str, 0,$ctx);2,max_requests参数配置不当,可能会引起间歇性502错误:
1 pm.max_requests = 1000  设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 ’0′ 则一直接受请求. 等同于 PHP_FCGI_MAX_REQUESTS 环境变量. 默认值: 0.
这段配置的意思是,当一个 PHP-CGI 进程处理的请求数累积到 500 个后,自动重启该进程。
  但是为什么要重启进程呢?
  一般在项目中,我们多多少少都会用到一些 PHP 的第三方库,这些第三方库经常存在内存泄漏问题,如果不定期重启 PHP-CGI 进程,势必造成内存使用量不断增长。因此 PHP-FPM 作为 PHP-CGI 的管理器,提供了这么一项监控功能,对请求达到指定次数的 PHP-CGI 进程进行重启,保证内存使用量不增长。
  正是因为这个机制,在高并发的站点中,经常导致 502 错误,我猜测原因是 PHP-FPM 对从 NGINX 过来的请求队列没处理好。不过我目前用的还是 PHP 5.3.2,不知道在 PHP 5.3.3 中是否还存在这个问题。
  目前我们的解决方法是,把这个值尽量设置大些,尽可能减少 PHP-CGI 重新 SPAWN 的次数,同时也能提高总体性能。在我们自己实际的生产环境中发现,内存泄漏并不明显,因此我们将这个值设置得非常大(204800)。大家要根据自己的实际情况设置这个值,不能盲目地加大。
  话说回来,这套机制目的只为保证 PHP-CGI 不过分地占用内存,为何不通过检测内存的方式来处理呢?我非常认同高春辉所说的,通过设置进程的峰值内在占用量来重启 PHP-CGI 进程,会是更好的一个解决方案。
3,php-fpm的慢日志,debug及异常排查神器:
  request_slowlog_timeout设置一个超时的参数,slowlog设置慢日志的存放位置
1 tail -f /var/log/www.slow.log  上面的命令即可看到执行过慢的php过程。
大家可以看到经常出现的网络读取超过、Mysql查询过慢的问题,根据提示信息再排查问题就有很明确的方向了。
php-fpm优化
1、php-fpm优化参数介绍
  他们分别是:pm、pm.max_children、pm.start_servers、pm.min_spare_servers、pm.max_spare_servers。

  • pm:表示使用那种方式,有两个值可以选择,就是static(静态)或者dynamic(动态)。
      在更老一些的版本中,dynamic被称作apache-like。这个要注意看配置文件的说明。

  下面4个参数的意思分别为:

  • pm.max_children:静态方式下开启的php-fpm进程数量
  • pm.start_servers:动态方式下的起始php-fpm进程数量
  • pm.min_spare_servers:动态方式下的最小php-fpm进程数
  • pm.max_spare_servers:动态方式下的最大php-fpm进程数量
  区别:

  • 如果dm设置为 static,那么其实只有pm.max_children这个参数生效。系统会开启设置数量的php-fpm进程。
  • 如果dm设置为 dynamic,那么pm.max_children参数失效,后面3个参数生效。
      系统会在php-fpm运行开始 的时候启动pm.start_servers个php-fpm进程,
    然后根据系统的需求动态在pm.min_spare_servers和pm.max_spare_servers之间调整php-fpm进程数

2、服务器具体配置
  对于我们的服务器,选择哪种执行方式比较好呢?事实上,跟Apache一样,运行的PHP程序在执行完成后,或多或少会有内存泄露的问题。
这也是为什么开始的时候一个php-fpm进程只占用3M左右内存,运行一段时间后就会上升到20-30M的原因了。
  对于内存大的服务器(比如8G以上)来说,指定静态的max_children实际上更为妥当,因为这样不需要进行额外的进程数目控制,会提高效率。
因为频繁开关php-fpm进程也会有时滞,所以内存够大的情况下开静态效果会更好。数量也可以根据 内存/30M 得到,比如8GB内存可以设置为100,
那么php-fpm耗费的内存就能控制在 2G-3G的样子。如果内存稍微小点,比如1G,那么指定静态的进程数量更加有利于服务器的稳定。
这样可以保证php-fpm只获取够用的内存,将不多的内存分配给其他应用去使用,会使系统的运行更加畅通。
  对于小内存的服务器来说,比如256M内存的VPS,即使按照一个20M的内存量来算,10个php-cgi进程就将耗掉200M内存,那系统的崩溃就应该很正常了。
因此应该尽量地控制php-fpm进程的数量,大体明确其他应用占用的内存后,给它指定一个静态的小数量,会让系统更加平稳一些。或者使用动态方式,
因为动态方式会结束掉多余的进程,可以回收释放一些内存,所以推荐在内存较少的服务器或VPS上使用。具体最大数量根据 内存/20M 得到。
比如说512M的VPS,建议pm.max_spare_servers设置为20。至于pm.min_spare_servers,则建议根据服务器的负载情况来设置,比如服务器上只是部署php环境的话,比较合适的值在5~10之间。
本服务器配置
1、服务器基本信息
  硬盘:数据盘30G、系统盘20G
内存:1.5G
CPU:双核
系统:CentOS 6.3 64位
带宽:独享2M
2、部署的应用
  Git、SVN、Apache、Tomcat、PHP、Nginx、Mysql、JDK
3、优化后的参数
1234 pm = dynamic pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 8
NGINX
./configure --user=www --group=www --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-pcre
检查是否安装成功
cd  /usr/local/nginx/sbin
./nginx -t
结果显示:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动nginx
cd  /usr/local/nginx/sbin 目录下面 输入 ./nginx 启动 nginx
检查是否启动成功
ie 浏览器中输入 http://192.168.15.132 (切换成自己的IP地址即可)  停止nginx
  pkill -9 nginx
  将NGINX添加为系统服务
  1、编写脚本,名为nginx
  vim /etc/init.d/nginx
  chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on

  更换NGINX启动方式 测试是否成功
service nginx start      启动
service nginx stop       停止
service nginx restart  重启
/etc/init.d/nginx 的内容如下
(改下里面的路径即可使用了):

#!/bin/sh
#
# nginx        Startup script for nginx
#
# chkconfig: - 85 15
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /opt/nginx/logs/nginx.pid
# description: nginx is a HTTP and reverse proxy server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop nginx
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/nginx ]; then
. /etc/sysconfig/nginx
fi
prog=nginx
nginx=${NGINX-/usr/local/nginx/sbin/nginx}
conffile=${CONFFILE-/usr/local/nginx/conf/nginx.conf}
lockfile=${LOCKFILE-/var/lock/subsys/nginx}
pidfile=${PIDFILE-/usr/local/nginx/logs/nginx.pid}
SLEEPMSEC=100000
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon --pidfile=${pidfile} ${nginx} -c ${conffile}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} ${prog}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
killproc -p ${pidfile} ${prog} -HUP
RETVAL=$?
echo
}
upgrade() {
oldbinpidfile=${pidfile}.oldbin
configtest -q || return 6
echo -n $"Staring new master $prog: "
killproc -p ${pidfile} ${prog} -USR2
RETVAL=$?
echo
/bin/usleep $SLEEPMSEC
if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then
echo -n $"Graceful shutdown of old $prog: "
killproc -p ${oldbinpidfile} ${prog} -QUIT
RETVAL=$?
echo
else
echo $"Upgrade failed!"
return 1
fi
}
configtest() {
if [ "$#" -ne 0 ] ; then
case "$1" in
-q)
FLAG=$1
;;
*)
;;
esac
shift
fi
${nginx} -t -c ${conffile} $FLAG
RETVAL=$?
return $RETVAL
}
rh_status() {
status -p ${pidfile} ${nginx}
}
# See how we were called.
case "$1" in
start)
rh_status >/dev/null 2>&1 && exit 0
start
;;
stop)
stop
;;
status)
rh_status
RETVAL=$?
;;
restart)
configtest -q || exit $RETVAL
stop
start
;;
upgrade)
upgrade
;;
condrestart|try-restart)
if rh_status >/dev/null 2>&1; then
stop
start
fi
;;
force-reload|reload)
reload
;;
configtest)
configtest
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"
RETVAL=2
esac
exit $RETVAL

##########################################################################
  编辑nginx配置文件,整合nginx与php
  说明:nginx默认页面路径已经更改为了/home/var/www;
  
location ~ \.php$ {
    root /home/var/www;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    include fastcgi_params;
}
  添加默认默认页面
index index.php index.htmlindex.htm;
  编辑fastcgi_params文件,如果为空或不存在该文件则创建并添加如下内容,如果已有内容则忽略如下步骤

vim /usr/local/nginx/conf/fastcgi_params --如果为空把原有内容更改如下,不为空则忽略:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //这一句如果默认配置文件里没有请手动添加进去,否则更改站点目录后PHP访问会出现not found
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
  更改NGINX默认站点目录
  vim /usr/local/nginx/conf/nginx.conf  (实际配置文件安装路径)注意替换下面的红色部位,具体NGINX优化安全设置,以后将单独文章做设置,敬请期待

将其中的       location / {           root html;           index index.php index.html index.htm;       }改为       location / {           root /home/var/www;           index index.php index.html index.htm;       }然后再将location ~ \.php$ {          root         html;          fastcgi_pass   127.0.0.1:9000;          fastcgi_index  index.php;          fastcgi_param  SCRIPT_FILENAME /script$fastcgi_script_name;
          include      fastcgi_params;       }改为location ~ \.php$ {          root         /home/var/www;          fastcgi_pass   127.0.0.1:9000;          fastcgi_index  index.php;          fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;          include      fastcgi_params;       }然后重启nginx 即可
  更改index.php页面内容

  vim /home/var/www/index.php
  <?php phpinfo(); ?>
  http://127.0.0.1/    浏览器打开  验证是否 整合NGINX+PHP-FPM 整合成功则出现 PHPINFO 页面信息。。。
  安装MEMCACHE,和OPCACHE扩展

  (因为php5.5X+版本已经内置了memcache和opcache扩展,所以不必另行下载,即可采用以下方式进行编译)

  1.memcache
  如果需要为php增加memcache扩展,按如下方法进行:
  cd /usr/local/php/bin
  ./pecl install memcache
  
  安装时会提示是否开启session支持,根据需要输入no 或者 yes,安装后路径如下:
  /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/memcache.so
  
  需要手动配置到php.ini中,增加如下内容,即表示启用memcache扩展:
  extension=memcache.so
  保存后,重启Apache,查看http://192.168.36.24/test.php进行验证。
  安装memcache服务
memcache各版本下载列表页: http://pecl.php.net/package/memcache
cd /home/happy/downloads
#这里我们选择的是memcache2.7版本的
wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar zvxf memcached-2.2.7.tgz
cd memcached-2.2.7
./configure --prefix=/usr/local/memcache
make
make install   
安装完后启动memcache并分配32m内存(32为使用内存数,可按自身情况修改) /usr/local/memcache/bin/memcached -d -m 32 -l 127.0.0.1 -p 11211 -u root
将memcached加入启动项
vim /etc/rc.d/rc.local   
在最后加入  
/usr/local/memcache/bin/memcached -d -m 32 -l 127.0.0.1 -p 11211 -u root
至此,整个memcache安装完毕
  

  2.Zend OPCache
  为了提高php运行速度,可以启用Zend OPCache,启用方法很简单,安照上面的方法安装php,则已经在
  /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/下生成了opcache.so,只需将其配置到php.ini中即可。
  vim  /usr/local/php/etc/php.ini
  找到[opcache]
  在其下面增加:
  zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/opcache.so
  然后打开并配置相应的配置项即可,比如:
  opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=5000
opcache.revalidate_freq=60
opcache.load_comments=1
  保存后,重启Apache,查看http://192.168.36.24/test.php进行验证。会看到如下信息:
  with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
3.redis安装
  redis-2.8.17tar.gz    官网下载地址    http://redis.io/download/
安装过程指令如下:
$ mkdir /usr/local/redis   
$ cd /home/Happy/down   
$ wget  http://download.redis.io/releases/redis-2.8.17.tar.gz
$ tar xzf redis-2.8.17.tar.gz  
$ cd redis-2.8.17  
$ make PREFIX=/usr/local/redis install #安装redis到指定目录中
注意上面的最后一行,我们通过PREFIX指定了安装的目录。如果make失败,一般是你们系统中还未安装gcc,那么可以通过yum安装: 1    yum install gcc
安装完成后,继续执行make.
在安装redis成功后,你将可以在/usr/local/redis看到一个bin的目录,里面包括了以下文件:
redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis-server
将redis做成一个服务
1.复制脚本到/etc/rc.d/init.d目录
ps: /etc/rc.d/init.d/目录下的脚本就类似与windows中的注册表,在系统启动的时候某些指定脚本将被执行
按以上步骤安装Redis时,其服务脚本位于:
/usr/local/src/redis/utils/redis_init_script  
必须将其复制到/etc/rc.d/init.d的目录下:
cp /usr/local/src/redis/utils/redis_init_script /etc/rc.d/init.d/redis
将redis_init_script复制到/etc/rc.d/init.d/,同时易名为redis。
如果这时添加注册服务:
chkconfig --add redis
将报以下错误:
redis服务不支持chkconfig
为此,我们需要更改redis脚本。
2.更改redis脚本
打开使用vi打开脚本,查看脚本信息: 1    vim /etc/rc.d/init.d/redis
看到的内容如下(下内容是更改好的信息):
#!/bin/sh  
#chkconfig: 2345 80 90  
# Simple Redis init.d script conceived to work on Linux systems  
# as it does use of the /proc filesystem.  
REDISPORT=6379  
EXEC=/usr/local/redis/bin/redis-server  
CLIEXEC=/usr/local/redis/bin/redis-cli  
PIDFILE=/var/run/redis_${REDISPORT}.pid  
CONF=&quot;/etc/redis/${REDISPORT}.conf&quot;
case &quot;$1&quot; in  
    start)  
        if [ -f $PIDFILE ]  
        then  
                echo &quot;$PIDFILE exists, process is already running or crashed&quot;
        else
                echo &quot;Starting Redis server...&quot;
                $EXEC $CONF &  
        fi  
        ;;  
    stop)  
        if [ ! -f $PIDFILE ]  
        then  
                echo &quot;$PIDFILE does not exist, process is not running&quot;
        else
                PID=$(cat $PIDFILE)  
                echo &quot;Stopping ...&quot;
                $CLIEXEC -p $REDISPORT shutdown  
                while [ -x /proc/${PID} ]  
                do
                    echo &quot;Waiting for Redis to shutdown ...&quot;
                    sleep 1  
                done  
                echo &quot;Redis stopped&quot;
        fi  
        ;;  
    *)  
        echo &quot;Please use start or stop as first argument&quot;
        ;;  
esac  
和原配置文件相比:
1.原文件是没有以下第2行的内容的,1    #chkconfig: 2345 80 90  
2.原文件EXEC、CLIEXEC参数,也是有所更改。
EXEC=/usr/local/redis/bin/redis-server   
CLIEXEC=/usr/local/redis/bin/redis-cli  
3.redis开启的命令,以后台运行的方式执行。1    $EXEC $CONF &  
ps:注意后面的那个“&”,即是将服务转到后面运行的意思,否则启动服务时,Redis服务将
占据在前台,占用了主用户界面,造成其它的命令执行不了。
4.将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf 1
2    mkdir /etc/redis     
cp /usr/local/src/redis/redis.conf /etc/redis/6379.conf
这样,redis服务脚本指定的CONF就存在了。默认情况下,Redis未启用认证,可以通过开启6379.conf的requirepass 指定一个验证密码。
以上操作完成后,即可注册yedis服务:1    chkconfig --add redis
3.启动redis服务 1    service redis start
将Redis的命令所在目录添加到系统参数PATH中
修改profile文件:
vi /etc/profile
在最后行追加:
export PATH=&quot;$PATH:/usr/local/redis/bin&quot;
然后马上应用这个文件:
/etc/profile   
这样就可以直接调用redis-cli的命令了,如下所示:
$ redis-cli   
redis 127.0.0.1:6379> auth superman   
OK   
redis 127.0.0.1:6379> ping   
PONG   
redis 127.0.0.1:6379>
至此,redis 就成功安装了。

  4.phpredis扩展安装
phpredis下载地址:https://github.com/nicolasff/phpredis
unzip phpredis-master.zip
cd phpredis-master
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
vi /usr/local/php/etc/php.ini
加入 extension=redis.so
重启php-fpm即可

  

  PHP安装中出现的常见问题及错误解决方法见下方:

  出现如下错误php安装出错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.,意思是,没有查找到mcrytp.h,需要安装libcrytp,在下面的地址下载libmarypt:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.8.tar.gz
  安装:
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.7
./configure
make
make install
或者直接yum install libmcrypt libmcrypt-devel 安装mcrypt依赖库
然后再安装PHP
centos 6.2 64位版本上安装LNMP,configure php的时候出现下面错误而退出  configure: error: Cannot find ldap libraries in /usr/lib
  解决办法:
  cp -frp /usr/lib64/libldap* /usr/lib/
然后再./configure.. ...重新编译即可
  error 1
  checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.

  (看提示就明白 是一个lib库没装  先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)
  解决办法
  yum install libxml2-devel.x86_64
  error 2
  checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>

  这是ssl没装
  解决办法
   yum  install  openssl.x86_64 openssl-devel.x86_64 -y
  error 3
  checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

  这是bzip2软件包没有安装
  解决办法
  yum install bzip2-devel.x86_64 -y
  error 4
  configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/

  curl和curl库文件没有安装
  解决办法
  yum install libcurl.x86_64 libcurl-devel.x86_64 -y
  error 5
  checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found

  GD库没有安装
  解决办法
  yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
  error 6
  checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

  libmcrypt库没有安装 ,要是不能用yun安装的话  就要去下载个gz包 自己编译安装
  (编译安装  ./configure   make && make install)

error7、configure: error: Cannot find ldap.h办法:yum install php-ldap.x86_64 -yyum install openldap-devel.x86_64 -y
error8、configure: error: Don’t know how to define struct flock on this system, set –enable-opcache=no解决方案:(注:修改后记得执行 chmod gu+x 给 /etc/ld.so.conf.d/local.conf文件添加可执行权限,否则无效)vim /etc/ld.so.conf.d/local.conf (local.conf可以随便起名称,以.conf为后缀就可,没有请创建文件并添加相应内容)添加/usr/local/lib (如果是64位系统 路径请写为 /usr/local/lib64或/usr/local/lib 具体根据实际lib地址路径)
:wq 保存ldconfig -v 生效(或者ldconfig)如果问题依然存在,则采用如下解决方法:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/    (具体依据mysql文件实际路径)
sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18 (具体更具mysql文件实际路径修改)

error9、error: Cannot find ldap libraries in /usr/lib 这个可能是由于libldap32和libldap64冲突:解决方法:cp -frp /usr/lib64/libldap* /usr/lib/
PHP5.4.45下make时出现如下错误时:
make
Generating phar.phar
chmod: 无法访问&quot;ext/phar/phar.phar&quot;: 没有那个文件或目录
make: [ext/phar/phar.phar] 错误 1 (忽略)
Build complete.
Don't forget to run 'make test'.
解决方法
解决:mkdir ext/phar/phar.phar -p
有关nginx的if(!-e)问题与解决方法
在配置URL重写时,启动NGINX出现如下错误提示
[iyunv@localhost nginx]# service nginx restart
nginx: [emerg] unknown directive &quot;if(!-e&quot; in /usr/local/nginx/conf/nginx.conf:48
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

一,nginx的url重写问题
vim  /usr/local/nginx/conf/nginx.conf
if (!-e $request_filename){
  //此处旋转url重写的规则
}
重起时,老师报如上红色部分错误。。
二,解决方法
原因是这样的:if和(之间必须有个空格。(小插曲,还好我有谷歌,百度就是坑,全市灌水SEO垃圾站,还是国外的网站靠谱,如果你遇到问题,尽量用谷歌翻译成英文到国外网站上去找答案,一找一个准)

  由于时间关系 PHP和NGINX安装后的详细配置部分暂时省略,后期添加
  zend Opcache配置参数详解
  我的最终如下,其余参数默认即可。
    opcache.memory_consumption=512
    opcache.max_accelerated_files=16229
    opcache.revalidate_freq=864000
    ;如果十天半月不改动 php 代码,上面的值尽可能高,单位是秒。
    ;如果改了,要么重启 apache,要么去上面那个控制面板里“Recheck”。
    opcache.enable_file_override=1
    opcache.force_restart_timeout=30
OPcache 配置参数中文版如下...(中文和英文同样让人难懂,两种语言文档都啃过了,基本才会了解...):
    opcache.enable(默认值:1)
    Zend Optimizer + 的开关, 关闭时代码不再优化.
    opcache.memory_consumption(默认值:64)
    Zend Optimizer + 共享内存的大小, 总共能够存储多少预编译的 PHP 代码(单位:MB).
    opcache.interned_strings_buffer(默认值:4)
    Zend Optimizer + 中interned字符串的占内存总量.(单位:MB)
    opcache.max_accelerated_files(默认值:2000)
    Zend Optimizer + 哈希表中键数量的最大值(一个脚本文件应当是对应一个key的,所以应当就是允许缓存的文件最大数量).
    这个值实际上是素数列表{ 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987 }中第一个大于设定值的数字.
    值设定范围: 200 – 100000
    opcache.max_wasted_percentage(默认值:5)
    “浪费”的内存达到此值对应的百分比,就会发起一个重启调度.
    opcache.use_cwd(默认值:1)
    开启这条指令, Zend Optimizer + 会自动将当前工作目录的名字追加到脚本键上, 以此消除同名文件间的键值命名冲突。
    关闭这条指令会提升性能,但是会对已存在的应用造成破坏.
    opcache.validate_timestamps(默认值:1)
    禁用时, 您必须手动重置Zend Optimizer +或重新启动Web服务器,以使文件系统的更改生效.
    检查的频率是由指令 “opcache.revalidate_freq” 控制.
    opcache.revalidate_freq(默认值:2)
    多久(以秒为单位)检查文件时间戳以改变共享内存的分配.”1″ 表示一秒校验一次, 但是是每个请求一次. “0″ 表示总是在校验.
    opcache.revalidate_path(默认值:0)
    允许或禁止在 include_path 中进行文件搜索的优化. 如果文件搜索被禁用而且可以在相同的 include_path 中找到这个缓存的文件,
    文件搜索就不会再进行下去了. 因此,如果 include_path 其它地方有一个同名文件的话, 那就找不到了.
    如果这个优化对您的应用有影响,那么应当允许它搜索. 默认情况下,指令是禁止的,这就意味着,优化是处于激活状态的.
    opcache.save_comments(默认值:1)
    如果禁用,所有的文档注释都从代码中剔除以此减少优化过的代码的大小.
    禁用 “文档注释” 可能会破坏一些现有的应用和框架(例如: Doctrine, ZF2, PHPUnit).
    opcache.load_comments(默认值:1)
    如果禁用, PHP文档注释将不会从 SHM(共享内存) 中读取. 尽管”文档注释”还是会被存储(save_comments=1),
    但是那些无论如何都用不上的注释就不必被应用读取了.
    opcache.fast_shutdown(默认值:0)
    如果开启, 一个快速关闭队列用以提速代码. 快速关闭队列并不释放每个已分配的块, 而是让 Zend 引擎内存管理器来干这个活.
    opcache.enable_file_override(默认值:0)
    允许覆盖文件存在(file_exists等)的优化特性。
    opcache.optimization_level(默认值:0xffffffff)
    一个位掩码,其中每个位允许或禁用相应的缓存通过.
    opcache.inherited_hack(默认值:1)
    启用此Hack可以暂时性的解决”can’t redeclare class”错误. Zend Optimizer + 存储着 DECLARE_CLASS 操作码使用继承的地方
    (这些是唯一可以被PHP执行的操作码,但是也可能因为优化引起的父类找不到而无法执行).
    当文件被读取时, Optimizer 会试着通过当前环境绑定被继承的类.
    这样做的问题是. DECLARE_CLASS 的操作码可能不被当前脚本所需要, 如果脚本需要操作码至少完成类的定义操作, 那么它就会无法执行.
    这指令的默认是禁用的, 这就表示优化是有效的. 该在 php 5.3 以及以上的版中不再被需要, 而且这个设置也不会生效.
    opcache.dups_fix(默认值:0)
    启用此Hack可以暂时性的解决”can’t redeclare class”错误.
    opcache.blacklist_filename(默认值:无)
    Zend Optimizer + 黑名单文件的位置.
    Zend Optimizer + 黑名单是一个文本文件包含了那些不能被加速的文件名.文件格式为每行一个文件名.
    文件名须为一个完整的路径或者紧紧一个文件前缀
    (如:/var/www/x 屏蔽了 /var/www 文件和目录中所有以 ‘x’ 开始的文件或者目录). 需要屏蔽的文件通常符合下面三个原因中的一个:
    1) 目录包含了自动生成的代码, 如 Smarty 或者 ZFW 的缓存.
    2) 执行加速时代码无法很好的运行, 从而耽误了编译时评估.
    3) 代码触发了一个 Zend Optimizer + 的 Bug
    opcache.max_file_size(默认值:0)
    通过文件大小屏除大文件的缓存.默认情况下所有的文件都会被缓存.
    opcache.consistency_checks(默认值:0)
    每 N 次请求检查一次缓存校验.默认值0表示检查被禁用了.由于计算校验值有损性能,这个指令应当紧紧在开发调试的时候开启.
    opcache.force_restart_timeout(默认值:180)
    从缓存不被访问后,等待多久后(单位为秒)调度重启.Zend Optimizer + 依托此指令来确定一个进程可能在处理过程中出现问题的情况.
    这段时间(等待时间)过后, 假设 Zend Optimizer + 发生了一些问题, 并开始干掉那些仍然持有预防重启锁的进程.
    当这些发生时, 如果日志的级别是3级或以上, 一个 “killed locker” 的错误就会被记录到 Apache 的日志中.
    opcache.error_log(默认值:无)
    Zend Optimizer + 的错误日志文件名.留空表示使用标准错误输出(stderr).
    opcache.log_verbosity_level(默认值:1)
    将错误信息都导向 Web 服务器日志.默认的只有致命错误(level 0) 或者错误(level 1)才会被记录.
    你也可以允许警告(level 2),提示消息(level 3) 或者 调试消息(level 4)被记录下来.
    opcache.preferred_memory_model(默认值:无)
    内存共享的首选后台.留空则是让系统选择.
    opcache.protect_memory(默认值:0)
    防止共享内存在脚本执行期间被意外写入, 仅用于内部调试.
    opcache.mmap_base(默认值:无)
    共享内存段映射基础(仅适用于Windows).所有的PHP进程必须映射到相同的共享内存地址空间.
    该指令用于手动修复 “Unable to reattach to base address” 错误.
  Zend Opcache之可视化PHP源代码:
  因为官方源码下载地址偶尔经常出现无法打开的问题,所以这里直接给出了zend opcache的可视化源代码,直接复制即可!

  
<?php
/*
OCP - Opcache Control Panel   (aka Zend Optimizer+ Control Panel for PHP)
Author: _ck_   (with contributions by GK, stasilok)
Version: 0.1.6
Free for any kind of use or modification, I am not responsible for anything, please share your improvements

* revision history
0.1.6  2013-04-12  moved meta to footer so graphs can be higher and reduce clutter
0.1.5  2013-04-12  added graphs to visualize cache state, please report any browser/style bugs
0.1.4  2013-04-09  added &quot;recheck&quot; to update files when using large revalidate_freq (or validate_timestamps=Off)
0.1.3  2013-03-30  show host and php version, can bookmark with hashtag ie. #statistics - needs new layout asap
0.1.2  2013-03-25  show optimization levels, number formatting, support for start_time in 7.0.2
0.1.1  2013-03-18  today Zend completely renamed Optimizer+ to OPcache, adjusted OCP to keep working
0.1.0  2013-03-17  added group/sort indicators, replaced &quot;accelerator_&quot; functions with &quot;opcache_&quot;
0.0.6  2013-03-16  transition support as Zend renames product and functions for PHP 5.5 (stasilok)
0.0.5  2013-03-10  added refresh button (GK)
0.0.4  2013-02-18  added file grouping and sorting (click on headers) - code needs cleanup but gets the job done
0.0.2  2013-02-14  first public release

* known problems/limitations:
Unlike APC, the Zend OPcache API
- cannot determine when a file was put into the cache
- cannot change settings on the fly
- cannot protect opcache functions by restricting execution to only specific scripts/paths

* todo:
Extract variables for prefered ordering and better layout instead of just dumping into tables
File list filter

*/

// ini_set('display_errors',1); error_reporting(-1);
if ( count(get_included_files())>1 || php_sapi_name()=='cli' || empty($_SERVER['REMOTE_ADDR']) ) { die; }  // weak block against indirect access

$time=time();
define('CACHEPREFIX',function_exists('opcache_reset')?'opcache_':(function_exists('accelerator_reset')?'accelerator_':''));

if ( !empty($_GET['RESET']) ) {
if ( function_exists(CACHEPREFIX.'reset') ) { call_user_func(CACHEPREFIX.'reset'); }
header( 'Location: '.str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) );
exit;
}

if ( !empty($_GET['RECHECK']) ) {
if ( function_exists(CACHEPREFIX.'invalidate') ) {
$recheck=trim($_GET['RECHECK']); $files=call_user_func(CACHEPREFIX.'get_status');
if (!empty($files['scripts'])) {
foreach ($files['scripts'] as $file=>$value) {
if ( $recheck==='1' || strpos($file,$recheck)===0 )  call_user_func(CACHEPREFIX.'invalidate',$file);
}
}
header( 'Location: '.str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) );
} else { echo 'Sorry, this feature requires Zend Opcache newer than April 8th 2013'; }
exit;
}

?><!DOCTYPE html>
<html>
<head>
<title>OCP - Opcache Control Panel</title>
<meta name=&quot;ROBOTS&quot; content=&quot;NOINDEX,NOFOLLOW,NOARCHIVE&quot; />

<style type=&quot;text/css&quot;>
body {background-color: #fff; color: #000;}
body, td, th, h1, h2 {font-family: sans-serif;}
pre {margin: 0px; font-family: monospace;}
a:link,a:visited {color: #000099; text-decoration: none;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse;}
.center {text-align: center;}
.center table { margin-left: auto; margin-right: auto; text-align: left;}
.center th { text-align: center !important; }
.middle {vertical-align:middle;}
td, th { border: 1px solid #000; font-size: 75%; vertical-align: baseline;}
h1 {font-size: 150%;}
h2 {font-size: 125%;}
.p {text-align: left;}
.e {background-color: #ccccff; font-weight: bold; color: #000; width:50%; white-space:nowrap;}
.h {background-color: #9999cc; font-weight: bold; color: #000;}
.v {background-color: #cccccc; color: #000;}
.vr {background-color: #cccccc; text-align: right; color: #000; white-space: nowrap;}
.b {font-weight:bold;}
.white, .white a {color:#fff;}
img {float: right; border: 0px;}
hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000;}
.meta, .small {font-size: 75%; }
.meta {margin: 2em 0;}
.meta a, th a {padding: 10px; white-space:nowrap; }
.buttons {margin:0 0 1em;}
.buttons a {margin:0 15px; background-color: #9999cc; color:#fff; text-decoration:none; padding:1px; border:1px solid #000; display:inline-block; width:5em; text-align:center;}
#files td.v a {font-weight:bold; color:#9999cc; margin:0 10px 0 5px; text-decoration:none; font-size:120%;}
#files td.v a:hover {font-weight:bold; color:#ee0000;}
.graph {display:inline-block; width:145px; margin:1em 0 1em 1px; border:0; vertical-align:top;}
.graph table {width:100%; height:150px; border:0; padding:0; margin:5px 0 0 0; position:relative;}
.graph td {vertical-align:middle; border:0; padding:0 0 0 5px;}
.graph .bar {width:25px; text-align:right; padding:0 2px; color:#fff;}
.graph .total {width:34px; text-align:center; padding:0 5px 0 0;}
.graph .total div {border:1px dashed #888; border-right:0; height:99%; width:12px; position:absolute; bottom:0; left:17px; z-index:-1;}
.graph .total span {background:#fff; font-weight:bold;}
.graph .actual {text-align:right; font-weight:bold; padding:0 5px 0 0;}
.graph .red {background:#ee0000;}
.graph .green {background:#00cc00;}
.graph .brown {background:#8B4513;}
</style>
<!--[if lt IE 9]><script type=&quot;text/javascript&quot; defer=&quot;defer&quot;>
window.onload=function(){var i,t=document.getElementsByTagName('table');for(i=0;i<t.length;i++){if(t.parentNode.className=='graph')t.style.height=150-(t.clientHeight-150)+'px';}}
</script><![endif]-->
</head>

<body>
<div class=&quot;center&quot;>

<h1><a href=&quot;?&quot;>Opcache Control Panel</a></h1>

<div class=&quot;buttons&quot;>
<a href=&quot;?ALL=1&quot;>Details</a>
<a href=&quot;?FILES=1&GROUP=2&SORT=3&quot;>Files</a>
<a href=&quot;?RESET=1&quot; onclick=&quot;return confirm('RESET cache ?')&quot;>Reset</a>
<?php if ( function_exists(CACHEPREFIX.'invalidate') ) { ?>
<a href=&quot;?RECHECK=1&quot; onclick=&quot;return confirm('Recheck all files in the cache ?')&quot;>Recheck</a>
<?php } ?>
<a href=&quot;?&quot; onclick=&quot;window.location.reload(true); return false&quot;>Refresh</a>
</div>

<?php

if ( !function_exists(CACHEPREFIX.'get_status') ) { echo '<h2>Opcache not detected?</h2>'; die; }

if ( !empty($_GET['FILES']) ) { echo '<h2>files cached</h2>'; files_display(); echo '</div></body></html>'; exit; }

if ( !(isset($_REQUEST['GRAPHS']) && !$_REQUEST['GRAPHS']) && CACHEPREFIX=='opcache_') { graphs_display(); if ( !empty($_REQUEST['GRAPHS']) ) { exit; } }

ob_start(); phpinfo(8); $phpinfo = ob_get_contents(); ob_end_clean();
// some info is only available via phpinfo? sadly buffering capture has to be used
if ( !preg_match( '/module\_Zend (Optimizer\+|OPcache).+?(\<table[^>]*\>.+?\<\/table\>).+?(\<table[^>]*\>.+?\<\/table\>)/s', $phpinfo, $opcache) ) { }  // todo

if ( function_exists(CACHEPREFIX.'get_configuration') ) { echo '<h2>general</h2>'; $configuration=call_user_func(CACHEPREFIX.'get_configuration'); }

$host=function_exists('gethostname')?@gethostname():@php_uname('n'); if (empty($host)) { $host=empty($_SERVER['SERVER_NAME'])?$_SERVER['HOST_NAME']:$_SERVER['SERVER_NAME']; }
$version=array('Host'=>$host);
$version['PHP Version']='PHP '.(defined('PHP_VERSION')?PHP_VERSION:'???').' '.(defined('PHP_SAPI')?PHP_SAPI:'').' '.(defined('PHP_OS')?' '.PHP_OS:'');
$version['Opcache Version']=empty($configuration['version']['version'])?'???':$configuration['version'][CACHEPREFIX.'product_name'].' '.$configuration['version']['version'];
print_table($version);

if ( !empty($opcache[2]) ) { echo preg_replace('/\<tr\>\<td class\=&quot;e&quot;\>[^>]+\<\/td\>\<td class\=&quot;v&quot;\>[0-9\,\. ]+\<\/td\>\<\/tr\>/','',$opcache[2]); }

if ( function_exists(CACHEPREFIX.'get_status') && $status=call_user_func(CACHEPREFIX.'get_status') ) {
$uptime=array();
if ( !empty($status[CACHEPREFIX.'statistics']['start_time']) ) {
$uptime['uptime']=time_since($time,$status[CACHEPREFIX.'statistics']['start_time'],1,'');
}
if ( !empty($status[CACHEPREFIX.'statistics']['last_restart_time']) ) {
$uptime['last_restart']=time_since($time,$status[CACHEPREFIX.'statistics']['last_restart_time']);
}
if (!empty($uptime)) {print_table($uptime);}
if ( !empty($status['cache_full']) ) { $status['memory_usage']['cache_full']=$status['cache_full']; }
echo '<h2 id=&quot;memory&quot;>memory</h2>';
print_table($status['memory_usage']);
unset($status[CACHEPREFIX.'statistics']['start_time'],$status[CACHEPREFIX.'statistics']['last_restart_time']);
echo '<h2 id=&quot;statistics&quot;>statistics</h2>';
print_table($status[CACHEPREFIX.'statistics']);
}

if ( empty($_GET['ALL']) ) { meta_display(); exit; }
if ( !empty($configuration['blacklist']) ) { echo '<h2 id=&quot;blacklist&quot;>blacklist</h2>'; print_table($configuration['blacklist']); }

if ( !empty($opcache[3]) ) { echo '<h2 id=&quot;runtime&quot;>runtime</h2>'; echo $opcache[3]; }

$name='zend opcache'; $functions=get_extension_funcs($name);
if (!$functions) { $name='zend optimizer+'; $functions=get_extension_funcs($name); }
if ($functions) { echo '<h2 id=&quot;functions&quot;>functions</h2>'; print_table($functions);  } else { $name=''; }

$level=trim(CACHEPREFIX,'_').'.optimization_level';
if (isset($configuration['directives'][$level])) {
echo '<h2 id=&quot;optimization&quot;>optimization levels</h2>';
$levelset=strrev(base_convert($configuration['directives'][$level], 10, 2));
$levels=array(
1=>'<a href=&quot;http://wikipedia.org/wiki/Common_subexpression_elimination&quot;>Constants subexpressions elimination</a> (CSE) true, false, null, etc.<br />Optimize series of ADD_STRING / ADD_CHAR<br />Convert CAST(IS_BOOL,x) into BOOL(x)<br />Convert <a href=&quot;http://www.php.net/manual/internals2.opcodes.init-fcall-by-name.php&quot;>INIT_FCALL_BY_NAME</a> + <a href=&quot;http://www.php.net/manual/internals2.opcodes.do-fcall-by-name.php&quot;>DO_FCALL_BY_NAME</a> into <a href=&quot;http://www.php.net/manual/internals2.opcodes.do-fcall.php&quot;>DO_FCALL</a>',
2=>'Convert constant operands to expected types<br />Convert conditional <a href=&quot;http://php.net/manual/internals2.opcodes.jmp.php&quot;>JMP</a>  with constant operands<br />Optimize static <a href=&quot;http://php.net/manual/internals2.opcodes.brk.php&quot;>BRK</a> and <a href=&quot;<a href=&quot;http://php.net/manual/internals2.opcodes.cont.php&quot;>CONT</a>',
3=>'Convert $a = $a + expr into $a += expr<br />Convert $a++ into ++$a<br />Optimize series of <a href=&quot;http://php.net/manual/internals2.opcodes.jmp.php&quot;>JMP</a>',
4=>'PRINT and ECHO optimization (<a href=&quot;https://github.com/zend-dev/ZendOptimizerPlus/issues/73&quot;>defunct</a>)',
5=>'Block Optimization - most expensive pass<br />Performs many different optimization patterns based on <a href=&quot;http://wikipedia.org/wiki/Control_flow_graph&quot;>control flow graph</a> (CFG)',
9=>'Optimize <a href=&quot;http://wikipedia.org/wiki/Register_allocation&quot;>register allocation</a> (allows re-usage of temporary variables)',
10=>'Remove NOPs'
);
echo '<table width=&quot;600&quot; border=&quot;0&quot; cellpadding=&quot;3&quot;><tbody><tr class=&quot;h&quot;><th>Pass</th><th>Description</th></tr>';
foreach ($levels as $pass=>$description) {
$disabled=substr($levelset,$pass-1,1)!=='1' || $pass==4 ? ' white':'';
echo '<tr><td class=&quot;v center middle'.$disabled.'&quot;>'.$pass.'</td><td class=&quot;v'.$disabled.'&quot;>'.$description.'</td></tr>';
}
echo '</table>';
}

if ( isset($_GET['DUMP']) ) {
if ($name) { echo '<h2 id=&quot;ini&quot;>ini</h2>'; print_table(ini_get_all($name,true)); }
foreach ($configuration as $key=>$value) { echo '<h2>',$key,'</h2>'; print_table($configuration[$key]); }
exit;
}

meta_display();

echo '</div></body></html>';

exit;

function time_since($time,$original,$extended=0,$text='ago') {
$time =  $time - $original;
$day = $extended? floor($time/86400) : round($time/86400,0);
$amount=0; $unit='';
if ( $time < 86400) {
if ( $time < 60)
{ $amount=$time; $unit='second'; }
elseif ( $time < 3600) { $amount=floor($time/60); $unit='minute'; }
else { $amount=floor($time/3600); $unit='hour'; }
}
elseif ( $day < 14)
{ $amount=$day; $unit='day'; }
elseif ( $day < 56)
{ $amount=floor($day/7); $unit='week'; }
elseif ( $day < 672) { $amount=floor($day/30); $unit='month'; }
else {   $amount=intval(2*($day/365))/2; $unit='year'; }
if ( $amount!=1) {$unit.='s';}
if ($extended && $time>60) { $text=' and '.time_since($time,$time<86400?($time<3600?$amount*60:$amount*3600):$day*86400,0,'').$text; }
return $amount.' '.$unit.' '.$text;
}

function print_table($array,$headers=false) {
if ( empty($array) || !is_array($array) ) {return;}
echo '<table border=&quot;0&quot; cellpadding=&quot;3&quot; width=&quot;600&quot;>';
if (!empty($headers)) {
if (!is_array($headers)) {$headers=array_keys(reset($array));}
echo '<tr class=&quot;h&quot;>';
foreach ($headers as $value) { echo '<th>',$value,'</th>'; }
echo '</tr>';  
}
foreach ($array as $key=>$value) {
echo '<tr>';
if ( !is_numeric($key) ) {
$key=ucwords(str_replace('_',' ',$key));
echo '<td class=&quot;e&quot;>',$key,'</td>';
if ( is_numeric($value) ) {
if ( $value>1048576) { $value=round($value/1048576,1).'M'; }
elseif ( is_float($value) ) { $value=round($value,1); }
}
}
if ( is_array($value) ) {
foreach ($value as $column) {
echo '<td class=&quot;v&quot;>',$column,'</td>';
}
echo '</tr>';
}
else { echo '<td class=&quot;v&quot;>',$value,'</td></tr>'; }
}
echo '</table>';
}

function files_display() {
$status=call_user_func(CACHEPREFIX.'get_status');
if ( empty($status['scripts']) ) {return;}
if ( isset($_GET['DUMP']) ) { print_table($status['scripts']); exit;}
$time=time(); $sort=0;
$nogroup=preg_replace('/\&?GROUP\=[\-0-9]+/','',$_SERVER['REQUEST_URI']);
$nosort=preg_replace('/\&?SORT\=[\-0-9]+/','',$_SERVER['REQUEST_URI']);
$group=empty($_GET['GROUP'])?0:intval($_GET['GROUP']); if ( $group<0 || $group>9) { $group=1;}
$groupset=array_fill(0,9,''); $groupset[$group]=' class=&quot;b&quot; ';
echo '<div class=&quot;meta&quot;>
<a ',$groupset[0],'href=&quot;',$nogroup,'&quot;>ungroup</a> |
<a ',$groupset[1],'href=&quot;',$nogroup,'&GROUP=1&quot;>1</a> |
<a ',$groupset[2],'href=&quot;',$nogroup,'&GROUP=2&quot;>2</a> |
<a ',$groupset[3],'href=&quot;',$nogroup,'&GROUP=3&quot;>3</a> |
<a ',$groupset[4],'href=&quot;',$nogroup,'&GROUP=4&quot;>4</a> |
<a ',$groupset[5],'href=&quot;',$nogroup,'&GROUP=5&quot;>5</a>
</div>';
if ( !$group ) { $files =& $status['scripts']; }
else {  
$files=array();
foreach ($status['scripts'] as $data) {
if ( preg_match('@^[/]([^/]+[/]){'.$group.'}@',$data['full_path'],$path) ) {
if ( empty($files[$path[0]])) { $files[$path[0]]=array('full_path'=>'','files'=>0,'hits'=>0,'memory_consumption'=>0,'last_used_timestamp'=>'','timestamp'=>''); }
$files[$path[0]]['full_path']=$path[0];
$files[$path[0]]['files']++;
$files[$path[0]]['memory_consumption']+=$data['memory_consumption'];
$files[$path[0]]['hits']+=$data['hits'];
if ( $data['last_used_timestamp']>$files[$path[0]]['last_used_timestamp']) {$files[$path[0]]['last_used_timestamp']=$data['last_used_timestamp'];}
if ( $data['timestamp']>$files[$path[0]]['timestamp']) {$files[$path[0]]['timestamp']=$data['timestamp'];}
}
}
}
if ( !empty($_GET['SORT']) ) {
$keys=array(
'full_path'=>SORT_STRING,
'files'=>SORT_NUMERIC,
'memory_consumption'=>SORT_NUMERIC,
'hits'=>SORT_NUMERIC,
'last_used_timestamp'=>SORT_NUMERIC,
'timestamp'=>SORT_NUMERIC
);
$titles=array('','path',$group?'files':'','size','hits','last used','created');
$offsets=array_keys($keys);
$key=intval($_GET['SORT']);
$direction=$key>0?1:-1;
$key=abs($key)-1;
$key=isset($offsets[$key])&&!($key==1&&empty($group))?$offsets[$key]:reset($offsets);
$sort=array_search($key,$offsets)+1;
$sortflip=range(0,7); $sortflip[$sort]=-$direction*$sort;
if ( $keys[$key]==SORT_STRING) {$direction=-$direction; }
$arrow=array_fill(0,7,''); $arrow[$sort]=$direction>0?' ▼':' ▲';
$direction=$direction>0?SORT_DESC:SORT_ASC;
$column=array(); foreach ($files as $data) { $column[]=$data[$key]; }
array_multisort($column, $keys[$key], $direction, $files);
}

echo '<table border=&quot;0&quot; cellpadding=&quot;3&quot; width=&quot;960&quot; id=&quot;files&quot;>
<tr class=&quot;h&quot;>';
foreach ($titles as $column=>$title) {
if ($title) echo '<th><a href=&quot;',$nosort,'&SORT=',$sortflip[$column],'&quot;>',$title,$arrow[$column],'</a></th>';
}
echo ' </tr>';
foreach ($files as $data) {
echo '<tr>
<td class=&quot;v&quot; nowrap><a title=&quot;recheck&quot; href=&quot;?RECHECK=',rawurlencode($data['full_path']),'&quot;>x</a>',$data['full_path'],'</td>',
($group?'<td class=&quot;vr&quot;>'.number_format($data['files']).'</td>':''),
'<td class=&quot;vr&quot;>',number_format(round($data['memory_consumption']/1024)),'K</td>',
'<td class=&quot;vr&quot;>',number_format($data['hits']),'</td>',              
'<td class=&quot;vr&quot;>',time_since($time,$data['last_used_timestamp']),'</td>',
'<td class=&quot;vr&quot;>',empty($data['timestamp'])?'':time_since($time,$data['timestamp']),'</td>
</tr>';
}
echo '</table>';
}

function graphs_display() {
$graphs=array();
$colors=array('green','brown','red');
$primes=array(223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987);
$configuration=call_user_func(CACHEPREFIX.'get_configuration');
$status=call_user_func(CACHEPREFIX.'get_status');

$graphs['memory']['total']=$configuration['directives']['opcache.memory_consumption'];
$graphs['memory']['free']=$status['memory_usage']['free_memory'];
$graphs['memory']['used']=$status['memory_usage']['used_memory'];
$graphs['memory']['wasted']=$status['memory_usage']['wasted_memory'];

$graphs['keys']['total']=$status[CACHEPREFIX.'statistics']['max_cached_keys'];
foreach ($primes as $prime) { if ($prime>=$graphs['keys']['total']) { $graphs['keys']['total']=$prime; break;} }
$graphs['keys']['free']=$graphs['keys']['total']-$status[CACHEPREFIX.'statistics']['num_cached_keys'];
$graphs['keys']['scripts']=$status[CACHEPREFIX.'statistics']['num_cached_scripts'];
$graphs['keys']['wasted']=$status[CACHEPREFIX.'statistics']['num_cached_keys']-$status[CACHEPREFIX.'statistics']['num_cached_scripts'];

$graphs['hits']['total']=0;
$graphs['hits']['hits']=$status[CACHEPREFIX.'statistics']['hits'];
$graphs['hits']['misses']=$status[CACHEPREFIX.'statistics']['misses'];
$graphs['hits']['blacklist']=$status[CACHEPREFIX.'statistics']['blacklist_misses'];
$graphs['hits']['total']=array_sum($graphs['hits']);

$graphs['restarts']['total']=0;
$graphs['restarts']['manual']=$status[CACHEPREFIX.'statistics']['manual_restarts'];
$graphs['restarts']['keys']=$status[CACHEPREFIX.'statistics']['hash_restarts'];
$graphs['restarts']['memory']=$status[CACHEPREFIX.'statistics']['oom_restarts'];
$graphs['restarts']['total']=array_sum($graphs['restarts']);

foreach ( $graphs as $caption=>$graph) {
echo '<div class=&quot;graph&quot;><div class=&quot;h&quot;>',$caption,'</div><table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>';
foreach ($graph as $label=>$value) {
if ($label=='total') { $key=0; $total=$value; $totaldisplay='<td rowspan=&quot;3&quot; class=&quot;total&quot;><span>'.($total>999999?round($total/1024/1024).'M':($total>9999?round($total/1024).'K':$total)).'</span><div></div></td>'; continue;}
$percent=$total?floor($value*100/$total):''; $percent=!$percent||$percent>99?'':$percent.'%';
echo '<tr>',$totaldisplay,'<td class=&quot;actual&quot;>', ($value>999999?round($value/1024/1024).'M':($value>9999?round($value/1024).'K':$value)),'</td><td class=&quot;bar ',$colors[$key],'&quot; height=&quot;',$percent,'&quot;>',$percent,'</td><td>',$label,'</td></tr>';
$key++; $totaldisplay='';
}
echo '</table></div>',&quot;\n&quot;;
}
}

function meta_display() {
?>
<div class=&quot;meta&quot;>
<a href=&quot;http://files.zend.com/help/Zend-Server-6/content/zendoptimizerplus.html&quot;>directives guide</a> |
<a href=&quot;http://files.zend.com/help/Zend-Server-6/content/zend_optimizer+_-_php_api.htm&quot;>functions guide</a> |
<a href=&quot;https://wiki.php.net/rfc/optimizerplus&quot;>wiki.php.net</a> |
<a href=&quot;http://pecl.php.net/package/ZendOpcache&quot;>pecl</a> |
<a href=&quot;https://github.com/zend-dev/ZendOptimizerPlus/&quot;>Zend source</a> |
<a href=&quot;https://gist.github.com/ck-on/4959032/?ocp.php&quot;>OCP latest</a>
</div>
<?php
}
?>
  
  

   
版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-139965-1-1.html 上篇帖子: LNMP启停控制自动脚本 下篇帖子: CentOS7 LNMP状态管理命令
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表