优化方法:
a.Compile PHP’s modules as less as possible, the simple the best (fast);
b.Increas PHP FastCGI child number to 100 and even more. Sometime, 200 is OK! ( On 4GB memory server);
c.Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;
d.Increase Linux “max open files”, using the following command (must be root):
e.Increase PHP-FPM open file description rlimit:
f.Using PHP code accelerator, e.g eAccelerator, XCache. And set “cache_dir” to /dev/shm on Linux.
====================================
A.减少编译模块,对应需要编译,后续的可以通过扩展添加。eAccelerator也是通过扩展添加的。
B.修改 /usr/local/php/etc/php-fpm.conf,单独应用单独修改对应conf文件。LINK:nginx php fpm多实例配置
[global]process.max = 128;进程数量警告值[www]pm = dynamic
pm.max_children = 5;调高监听进程数量 |
C.参考nginx php fpm多实例配置当中nginx.cnf连接PHP方法”fastcgi_pass unix:/tmp/php-cgi-nodeA.sock;”
D.调高linux内核打开文件数量
echo 'ulimit -HSn 65536' >> /etc/profileecho 'ulimit -HSn 65536' >> /etc/rc.localsource /etc/profile#对应php-fpm.conf中rlimit_core,默认linux内核打开文件数量 |
E.修改 /usr/local/php/etc/php-fpm.conf,调高rlimit_files值
[global]rlimit_files = 2048[www]rlimit_files = 2048 |
F.利用php代码加速器eAccelerator
加速引擎: memcache、eAccelerator
创建www用户做web执行用户
groupadd www
useradd -r -g www -s /sbin/nologin www |
F.1.memcache模块
简介:Memcache模块提供了于memcached方便的面向过程及面向对象的接口,memcached是为了降低动态web应用
从数据库加载数据而产生的一种常驻进程缓存产品。Memcached是一个高性能分布式的内存对象缓存系统,
通常被用于降低数据库加载压力以提高动态web应用的响应速度。
Memcached提供系统内存缓存-Memcache提供PHP接口
代码包:libevent-2.0.21-stable.tar.gz、memcached-1.4.15.tar.gz、memcache-2.2.7.tgz
memcached依赖libevent
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make && make installecho '/usr/local/lib/' > /etc/ld.so.conf.d/libevent.conf
ldconfig |
tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15
./configure --prefix=/usr/local/memcachedmake && make install#-d daemon模式 -m shared memory -c number of processes -p port -u userln -s /usr/local/memcached/bin/memcached /usr/local/bin/memcachedecho "/usr/local/memcached/bin/memcached -d -m 128 -c 1024 -p 11211 -u www" >> /etc/rc.d/rc.localecho "/usr/local/memcached/bin/memcached -d -m 32 -c 512 -p 11212 -u www" >> /etc/rc.d/rc.local/usr/local/memcached/bin/memcached -d -m 128 -c 1024 -p 11211 -u www/usr/local/memcached/bin/memcached -d -m 32 -c 512 -p 11212 -u www |
tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7/usr/local/php/bin/phpize
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir=/usr/local/zlibmake && make install |
编辑php.ini
F.2.eAccelerator模块
简介:eAccelerator的是一个免费开源的PHP加速、优化器。通过在编译状态下对它们进行缓存以提高PHP脚本的性能,所以那些
系统开销在编译时几乎可以被消除。优化脚本,以加快其执行。eAccelerator在通常会降低服务器的负载和并提高PHP代码的执行时间。
tar zxvf eaccelerator-eaccelerator-42067ac.tar.gz
cd eaccelerator-eaccelerator-42067ac/usr/local/php/bin/phpize
./configure --enable-eaccelerator --with-php-config=/usr/local/php/bin/php-config
make && make install#cp eAccelerator control panel 到网站目录mkdir /WEB ROOT PATH/eaccelerator/cp control.php /WEB ROOT PATH/eaccelerator/index.php |
修改php.ini添加
extension="eaccelerator.so"eaccelerator.shm_size="64" #不能超过Linux 系统的核心参数共享内存(M)eaccelerator.cache_dir="/tmp/eaccelerator"eaccelerator.enable="1"eaccelerator.optimizer="1"eaccelerator.check_mtime="1"eaccelerator.debug="0"eaccelerator.log_file = "/WEB ROOT PATH/eaccelerator/eaccelerator_log"eaccelerator.filter=""eaccelerator.shm_max="0"eaccelerator.shm_ttl="0"eaccelerator.shm_prune_period="0"eaccelerator.shm_only="0"eaccelerator.compress="1"eaccelerator.compress_level="9"eaccelerator.keys = "shm_and_disk"eaccelerator.session = "shm_and_disk"eaccelerator.content = "shm_and_disk" #参数:shm_and_disk(默认)/shm/shm_only/disk_only/noneeaccelerator.allowed_admin_path = "/WEB ROOT PATH/eaccelerator" |
创建缓存文件夹
mkdir /tmp/eacceleratorchown -R www:www /tmp/eacceleratorchmod 777 /tmp/eacceleratorecho "mkdir /tmp/eaccelerator" >> /etc/rc.d/rc.localecho "chown -R www:www /tmp/eacceleratorr" >> /etc/rc.d/rc.localecho "chmod 777 /tmp/eaccelerator" >> /etc/rc.d/rc.local |
————————————
配置Linux 系统的核心参数共享内存(130M)
echo 'kernel.shmmax = 136314880 ' >> /etc/sysctl.conf/sbin/sysctl -p