近期由于appfog的免费套餐不让用了,将自己的blog站点从国外迁移到阿里云上。阿里云的配置为1核cpu 1G memory ,最初使用的是nginx + php-fpm的组合 。在使用了更种cache和cdn手段优化后,打开伪静态页面时速度还可以。不过在打开page页面时出奇的慢。使用we
近期由于appfog的免费套餐不让用了,将自己的blog站点从国外迁移到阿里云上。阿里云的配置为1核cpu 1G memory ,最初使用的是nginx + php-fpm的组合 。在使用了更种cache和cdn手段优化后,打开伪静态页面时速度还可以。不过在打开page页面时出奇的慢。使用web在线测试工具后排除了网络自身的问题(当前办公环境的网络挺烂,上个外网都要各种代理)后,登陆云主机查看进程信息和资源信息后,发现在打开page页时,php-fpm进程cpu使用率一直维持在99% ~ 100% 。
在尝试使用xcache 、apache + mod_php 等各种优化组合后问题依旧不见好转。万般无奈之下决定尝试使用facebook 开发的神器 ———— hhvm 。
HHVM(HipHop Virtual Machine)会将PHP代码转换成高级别的字节码(通常称为中间语言)。然后在运行时通过即时(JIT)编译器将这些字节码转换为x64的机器码。在这些方面,HHVM十分类似与C#的CLR和Java的JVM。
2008年Facebook就开始使用HipHop(现在成为HPHP),这是一种PHP执行引擎;最初是为了将Fackbook的大量PHP代码转成C++,以提高性能和节约资源。最初的版本成为HPHPc,是一个PHP到C++的编译器。
2010年初,facebook将HipHop平台开源,在后续的发展中,hiphop开发出更高的版本,也就是HHVM 。HHVM加强了HPHPc的健壮性,同时还修复了许多重要错误。
这里以centos6.x为例,增加epel 及gleez 源,并安装hhvm:
#增加epel源,并安装相关依赖包 rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel mysql-devel\ libxml2-devel libicu-devel pcre-devel gd-devel boost-devel sqlite-devel pam-devel \ bzip2-devel oniguruma-devel openldap-devel readline-devel libc-client-devel libcap-devel \ libevent-devel libcurl-devel libmemcached-devel #增加gleez源,并安装hhvm rpm -Uvh http://yum.gleez.com/6/x86_64/gleez-repo-6-0.el6.noarch.rpm yum -y install hhvm
除了gleez源,也可以使用hop5源:
wget http://www.hop5.in/yum/el6/hop5.repo yum clean all yum install hhvm
安装完成后,可以通过以下命令查看进行确认:
[root@91it ~]# hhvm -a Welcome to HipHop Debugger! Type "help" or "?" for a complete list of commands. Note: no server specified, debugging local scripts only. If you want to connect to a server, launch with "-h" or use: [m]achine [c]onnect <servername> hphpd>
注:ubuntu、mint、debian等其他平台的安全这里就不再介绍,安装时具体可以参看hhvm 在 github上的wiki 介绍 。
hhvm有三种运行模式:web服务器模式、fastcgi 模式、socket模式
类似于python、ruby的web框架运行模式,hhvm可以不依赖其他web服务器,直接以web模式运行。其可以通过以下命令直接运行:
/usr/bin/hhvm --mode server --user www -vServer.Port=80
也可以通过读取配置文件进行运行:
#cat /etc/hhvm.hdf
Server {
Port = 80
SourceRoot = /var/www/ #指定web站点的根目录
}
Eval {
Jit = true
}
Log {
Level = Error
UseLogFile = true
File = /var/log/hhvm/error.log
Access {
* {
File = /var/log/hhvm/access.log
Format = %h %l %u %t \"%r\" %>s %b
}
}
}
#指定虚拟主机
VirtualHost {
* {
Prefix = blog.361way.com
#这里是Server节点 SourceRoot根目录下的子目录名称,本例中表示虚拟主机位于/var/www/blog
PathTranslation = blog
CheckExistenceBeforeRewrite = true
#虚拟主机域名
ServerName = www.361way.com
Pattern = .*
RewriteRules {
dirindex {
pattern = ^/(.*)/$
to = $1/index.php
qsa = true
}
}
}
}
#指定静态文件及规则
StaticFile {
FilesMatch {
* {
pattern = .*\.(dll|exe)
headers {
* = Content-Disposition: attachment
}
}
}
Extensions {
css = text/css
gif = image/gif
html = text/html
jpe = image/jpeg
jpeg = image/jpeg
jpg = image/jpeg
png = image/png
tif = image/tiff
tiff = image/tiff
txt = text/plain
}
}可以通过下面的命令通过读取配置文件直接运行:
/usr/bin/hhvm --mode daemon --user www-data --config /etc/hhvm.hdf
hhvm也可以像php-fpm 一样,通过监听某个端口,前端通过apache、nginx进行反向代理进行访问,如监听在9000端口,就可以通过以下命令运行:
/usr/bin/hhvm --mode daemon --user www -vServer.Type=fastcgi -vServer.Port=9000
以前端为nginx为例,nginx的反向代理配置部分如下 ( 可以看出和使用php-fpm模式没什么区别 ):
location ~ .*\.(hh|php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}同样也可以通过读取配置文件,配置更多的参数,hhvm配置文件如下:
# cat /etc/hhvm/server.hdf
PidFile = /var/run/hhvm/pid
Server {
Port = 9000
Type=fastcgi
# File_socket = /var/run/hhvm/hhvm.sock
# SourceRoot = /var/www/
DefaultDocument = index.php
}
Log {
Level = Warning
AlwaysLogUnhandledExceptions = true
RuntimeErrorReportingLevel = 8191
UseLogFile = true
UseSyslog = false
File = /var/log/hhvm/error.log
Access {
* {
File = /var/log/hhvm/access.log
Format = %h %l %u % t \"%r\" %>s %b
}
}
}
Repo {
Central {
Path = /var/log/hhvm/.hhvm.hhbc
}
}
#include "/usr/share/hhvm/hdf/static.mime-types.hdf"
StaticFile {
FilesMatch {
* {
pattern = .*\.(dll|exe)
headers {
* = Content-Disposition: attachment
}
}
}
Extensions : StaticMimeTypes
}
MySQL {
TypedResults = false
}
通过以下命令读取配置文件运行:
/usr/bin/hhvm --config /etc/hhvm/server.hdf --user www --mode daemon
该模式大部分配置文件同fastcgi 模式下的参数一致,这点和php-fpm 运行在端口模式与socket模式一样。运行socket模式下需要开启下面配置中的参数:
# File_socket = /var/run/hhvm/hhvm.sock
同样,也可以直接在命令行中增加vserver.file_socket参数进行运行。
ECTouch是上海商创网络科技有限公司推出的一套基于 PHP 和 MySQL 数据库构建的开源且易于使用的移动商城网店系统!应用于各种服务器平台的高效、快速和易于管理的网店解决方案,采用稳定的MVC框架开发,完美对接ecshop系统与模板堂众多模板,为中小企业提供最佳的移动电商解决方案。ECTouch程序源代码完全无加密。安装时只需将已集成的文件夹放进指定位置,通过浏览器访问一键安装,无需对已有
0
相对于原生的php,网上很多人评测hhvm是原生的5-6倍的有之,10-20倍的亦有之。且不管网上的这些评测结果,单说我在阿里云上运行的效果。页面打开的速度显然较之前快了不止一倍,而且较之前使用php-fpm的方式运行,稳定性也有所增强。根据我当前的配置hhvm进程占用内存在20%左右(200M左右),当有页面进行解析时,也基本维持在这个范围,这点很类似java的jvm模式 ,预先将内存点用。
通过查询发现,hhvm使用了以下技术:
通过以上技术,HipHop和HHVM获得了性能的提升。
原文地址:centos6.5使用hhvm为wordpress加速, 感谢原作者分享。
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号