背景:Newest 'owncloud' Questions - Stack Overflow Track down PHP error “Comments starting with '#' are deprecated in Unknown on line 1 at Unknown#0” I've just set up a RPi 2 with the latest ...

PHP Deprecated: Comments starting with '#' are deprecated in *.ini 警告解决办法

新装的CentOS7 64系统,使用新立得装的PHP 版本,但是每次我在命令行下执行php脚本时都会出如下的警告信息:

PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0

上网查了一下,原来是新版本的PHP不赞成用'#'号作为注释符号,需要用分号';'。打开这个文件,把里面的#替换成;号,问题解决!

摘自:http://blog.csdn.net/rainday0310/article/details/6330115

Shell脚本风格的单行注释

  这种注释方式使用"#"的形式实现,它的用法与C++语言风格注释方式相似。使用Shell脚本风格进行单行注释的PHP示例代码如下:



参考:http://jackxiang.com/post/6532/
背景:写PHP时特别是调试页面时,不想有额外输出,于是相应的的调试插件出现了。
以前寫PHP都用var_dump來debug
現在改用ChromePHP來debug
ChromePHP是Chrome上的套件
在Firefox上也有Firephp
ChromePHP使用上也非常簡單
先到chrome web store
安裝ChromePHP套件
在去ChromePHP官網下載ChromePhp.php檔案
chromephp官網:http://www.chromephp.com/
接著只有在需要用的時後
include 'ChromePhp.php';
ChromePhp::log('需要輸出的var');
這樣一來就可以在Chrome控制台上的console看到輸出的訊息
如果要在CodeIgniter上使用
需要修改一下ChromePhp.php
把用本的private function __construct()
修改為public function __construct()
$this->load->library('ChromePhp');
$this->chromephp->log('需要輸出的var');
来自:http://blog.ipushs.com/codeigniter%E7%94%A8chromephp%E4%BE%86debugphp/?replytocom=78
最近研究安全性时,偶尔发现php.ini上并没有开启open_basedir,于是搜索了下,有人说开启后有性能影响,于是测试了一下。

首先,交代一下环境:centos + nginx + php-fpm + php + mysql,典型的lnmp了。

测试代码如下:
Php代码  收藏代码

执行100次,实测结果是未开启open_basedir时大约是0.00001秒。
开启后:0.001秒。
性能相差100倍。

在安全性和性能上,该怎么取舍呢。。。还是安全性吧?哈哈。。。

来自:http://exvision.iteye.com/blog/830506
背景:在一个项目中,有一个兄弟用init jquery时,用了这种写法,而不是$().ready(   ,参考:http://jackxiang.com/post/1983/ ,于是了解了一下~

学习一:
提问,
(function(window,undefined){})(window);
这个,为什么要将window和undefined作为参数传给它?
回答:
因为 javascript 执行JS代码是从里到外,因此把全局变量传进来,就避免了到外层去寻找。提高效率

提问Q:
不明白为什么JS 的undefined还可以做变量名。 undefined算是JS里面的什么呢?不是关键字,不是保留字,true跟false还有null也不是,不过跟undefined不同,不能用作变量名。
这些到底算是什么呢?
回答A:
可以避免 undefined 被别人定义了。
var undefined=8;
(function(window){
alert(window.undefined); //8
alert(undefined); //8
})(window);

var undefined=8;
(function(window,undefined){
alert(window.undefined); //8
alert(undefined); //此处undefined参数为局部的名称为undefined变量,值为undefined
})(window);

所以后者,就算外面的人把 ,undefined 定义了,里面的 undefined 依然不受影响。
大概是为了最大程度防止外界的变量定义对 所做封装的内部影响吧。

学习二,更和jquery结合更紧密:
详解jquery插件中(function ( $, window, document, undefined )的作用:
在jquery插件中我们经常看到以下这段代码
;(function ( $, window, document, undefined ){
//函数体内具体代码
})(jQuery, window,document);
对于很多初学者来说很难明白这表示什么,下边我将为大家介绍其相应的作用。

1、代码最前面的分号,可以防止多个文件压缩合并以为其他文件最后一行语句没加分号,而引起合并后的语法错误。

2、匿名函数(function(){})();:由于Javascript执行表达式是从圆括号里面到外面,所以可以用圆括号强制执行声明的函数。避免函数体内和外部的变量冲突。

3、$实参:$是jquery的简写,很多方法和类库也使用$,这里$接受jQuery对象,也是为了避免$变量冲突,保证插件可以正常运行。

4、window, document实参分别接受window, document对象,window, document对象都是全局环境下的,而在函数体内的window, document其实是局部变量,不是全局的window, document对象。这样做有个好处就是可以提高性能,减少作用域链的查询时间,如果你在函数体内需要多次调用window 或 document对象,这样把window 或 document对象当作参数传进去,这样做是非常有必要的。当然如果你的插件用不到这两个对象,那么就不用传递这两个参数了。

5、最后剩下一个undefined形参了,那么这个形参是干什么用的呢,看起来是有点多余。undefined在老一辈的浏览器是不被支持的,直接使用会报错,js框架要考虑到兼容性,因此增加一个形参undefined


http://www.bcty365.com/content-47-805-1.html









————————————————————为何有这一问(代码来自)————————————————————


代码来自:
http://jackxiang.com/post/7864/

更多疑问参考解答Url:http://zhidao.baidu.com/link?url=P4soG5CQSsXaZUo5DBfUX9uoFl9Mkbncf_dFs7CdC3XwdVdy7rSjWCAyTy4VWIMtIAkRzpV87TJh6uHxlvYPyq
CentOS 7下hhvm Nginx环境搭建:
http://www.linuxeye.com/Linux/2029.html
Supervisor管理hhvm进程:
http://www.linuxeye.com/Linux/Supervisor-hhvm.html
注意一下路径:
;logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile=/data/logs/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)

=======================================================
Q:多处出现:软件包boost-regex-1.54.0-9.el6.x86_64.rpm没有签名?
Q:大家都用source编译?我是想通过yum 安装了解一下php的hhvm 尽量用yum 安装。
A:比较容易标准化 机器多的话,可以统一标准化 对,标准化很重要
https://github.com/lj2007331/lnmp
淘宝一个人建的,其中functions目录把每个l n/a mp版本安装封装成了一个shell函数(包含了依赖包),有hhvm和php7。如果是在机器上体验一下,可以使用这个项目或者把他的函数抠出来,可以省去从源码编译挨个找依赖包的痛苦。

————————————————兼容过渡办法—————————————————

测试了下6月6日下载编译的PHP7和HHVM最新的3.7.1.
ab -c100 -n1000 http://127.0.0.1/wordpress/
100并发完成1000个请求,PHP7(开启opcache,5个PHP-FPM工作进程)每秒处理117个请求,HHVM则是每秒126个,性能差距很小.值得一提的是,HHVM没有热身时(第一次压测),每秒只能处理56个请求,而PHP7仍能处理117个请求.

这是我6月6日编译的PHP7开发版,你可以下载进行测试:
http://my.oschina.net/eechen/blog/411534

补充:
如果你觉得处于Alpha版本的PHP7还不够稳定,你可以配置Nginx,PHP7-FPM监听9000端口,PHP5-FPM监听9001端口,当PHP7崩掉的时候自动切换到作为备用的PHP5.

upstream php.backend {
    server 127.0.0.1:9000;
    server 127.0.0.1:9001 backup;
}
PHP-FPM是多进程的架构,PHP7并没有改动PHP-FPM的架构,所以说就算PHP-FPM工作进程因为内置的PHP7引擎发生故障,我估计也就工作进程会崩溃退出,而PHP-FPM的master进程会自动重启一个新的工作进程.
————————————————————————————————————————————————————

已加载插件:fastestmirror, refresh-packagekit, security
/var/run/yum.pid 已被锁定,PID 为 8085 的另一个程序正在运行。
另外一个程序锁定了 yum;等待它退出……
  The other application is: PackageKit
    Memory :  22 M RSS (328 MB VSZ)
    Started: Mon May  4 16:41:46 2015 - 00:09 ago
    State  : Uninterruptible, pid: 8085
另外一个程序锁定了 yum;等待它退出……
  The other application is: PackageKit
    Memory :  31 M RSS (339 MB VSZ)
    Started: Mon May  4 16:41:46 2015 - 00:11 ago
你怎么2个东西在跑,kill:


重复执行 install.sh

ps -ef | grep hhvm
service hhvm start

find . -name "hhvm"
./etc/rc.d/init.d/hhvm
./var/run/hhvm
./var/log/hhvm

如果说想配置nginx+hhvm,我用nginx+hhvm可以吧?
vhost.sh

最后,
mysql源码安装的是 mysql-server
mysql x86_64是客户端,别搞错。

还是有问题:
错误:Package: mysql-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient_r.so.16(libmysqlclient_16)(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient_r.so.16(libmysqlclient_16)(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-devel-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient_r.so.16()(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient_r.so.16()(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient.so.16()(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient.so.16()(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient_r.so.16()(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient_r.so.16()(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient.so.16(libmysqlclient_16)(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient.so.16(libmysqlclient_16)(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-devel-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient.so.16()(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient.so.16()(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
You could try using --skip-broken to work around the problem
问题在:
lnmp.org安装了mysql-
有可能不行 php 用的 mysql库 就有问题。

删除这个包就Ok了?mysql-libs-5.5.43-1.el6.remi.x86_64

Q:干嘛不用我的来安装 整套?
A:历史原因啊。
Q:删除两个?
rpm -e  mysql-libs-5.5.43-1.el6.remi.x86_64
rpm -e   mysql-5.5.43-1.el6.remi.x86_64

A:
rpm -e mysql-5.1.73-3.el6_5.x86_64  删掉

回家后实践,如下且成功:
rpm -qa |grep mysql
mysql-devel-5.5.43-1.el6.remi.x86_64
mysql-libs-5.5.43-1.el6.remi.x86_64
mysql-5.5.43-1.el6.remi.x86_64
实践是这样的:
rpm -e mysql-devel-5.5.43-1.el6.remi.x86_64
rpm -e mysql-5.5.43-1.el6.remi.x86_64      
rpm -e mysql-libs-5.5.43-1.el6.remi.x86_64

于是重新安装一次并重启:
./install.sh
________
ps aux|grep hhvm
www       3155 55.0  2.5 676320 150628 ?       R    22:56   0:09 /usr/bin/hhvm --mode server --user www --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf


修改/usr/local/nginx/conf/nginx.conf使其中一段成为如下:

        location ~ .*\.(php|php5)?$  {
                #fastcgi_pass  unix:/data/runsock/php-cgi.sock;
                fastcgi_pass   unix:/data/runsock/hhvmsock/hhvm.sock;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include        fastcgi_params;
                include        fastcgi_params;
                }
service nginx reload
详细配置看后面,安装就按上面安装得了。依赖太多,太麻烦了。

ps aux|grep hhvm  
www       3155  3.3  2.8 880828 172836 ?       Sl   23:23   0:22 /usr/bin/hhvm --mode server --user www --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf
strace  -f -p 3155 //访问一下看有无输出,实践是有输出的。说明安装成功了。


CentOS7 hhvm交给supervisord管理了:
ps -ef | grep super supervisord 这个进程在吗?
service supervisord restart

最后解决,开机这个/var/run/hhvm 会不见了(CentOS7里估计是一个内存磁盘,重启就没了,导致启动失败。),呵,开机就创建好了:
创好是这样的: ls /var/run/hhvm/
hhvm.hhbc  pid  sock


配置hhvm
# vi /etc/hhvm/server.ini


vi /etc/hhvm/php.ini



一个www的hhvm去读取一个mysql.sock,
而我的sock是放在一个mysql的组目录下,如何实现无permission Denny的读取?
所以得注意权限,如下所示 :
[root@iZ25z0ugwgtZ runsock]# ll /data/runsock
drwxrwxrwx 2 www   www   4096 2月  17 17:30 hhvm
drwxrwxrwx 2 mysql mysql 4096 2月  17 17:28 mysqlsock
drwxrwxrwx 2 www   www   4096 2月  17 17:30 phpsock

因为hhvm是www运行,而mysql是mysql运行,这块hhvm去读取mysql的sock时, mysql这个sock上层目录是mysql,导致不能读取,于是得对mysql的这个sock进行777,chmod -R 777 /data/runsock/mysqlsock :
cd /data
chown -R www:www runsock hhvm logs
chmod -R 777 runsock hhvm logs

访问后是502,如下修改:
./jackxiang.conf:       fastcgi_pass   unix:/var/run/hhvm/sock;修改:
./jackxiang.conf:       fastcgi_pass   unix:/data/runsock/hhvmsock/hhvm.sock;

于是,就好了?没有,必须重启动nginx,而不是reload,
connect() to unix:/var/run/hhvm/sock failed (2: No such file or directory) while connecting to upstream, client: 106.37.79.53, server: jackxiang.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/hhvm/sock:", host: "jackxiang.com"

pkill -9 nginx //否则会出现还是找原来的sock:
../sbin/nginx
这样就不用前面的每次开机建立如下目录和赋权限:

centOs7.0也就可以使用hhvm了,性能用在wordpress上,结合前端nginx的cache插件相当不错~
———————————————————安装问题—————————————————————————
yum -y --nogpgcheck install hhvm 出现:
--> 处理依赖关系 libwebp.so.4()(64bit),它被软件包 hhvm-3.5.0-4.el6.x86_64 需要
--> 完成依赖关系计算
错误:Package: hhvm-3.5.0-4.el6.x86_64 (gleez)
          Requires: libwebp.so.4()(64bit)
You could try using --skip-broken to work around the problem

出现:
一)源码安装webp库:
先下载libwebp-0.3.0.tar.gz
tar -zxvf libwebp-0.3.0.tar.gz
cd libwebp-0.3.0
./configure && make && make install
cp /usr/local/lib/libwebp.so.4.0.2 /usr/lib64/
ln -s /usr/lib64/libwebp.so.4.0.2 /usr/lib64/libwebp.so.4
ln -s /usr/lib64/libwebp.so.4.0.2 /usr/lib64/libwebp.so

二)yum search libwebp :
libwebp-devel.i686 : Development files for libwebp, a library for the WebP format
libwebp-devel.x86_64 : Development files for libwebp, a library for the WebP format
libwebp-java.x86_64 : Java bindings for libwebp, a library for the WebP format
libwebp.i686 : Library and tools for the WebP graphics format
libwebp.x86_64 : Library and tools for the WebP graphics format
libwebp-tools.x86_64 : The WebP command line tools

处理依赖关系 libwebp.so.4()(64bit),它被软件包 hhvm-3.5.0-4.el6.x86_64 需要,于是:
root@119.10.6.23:~# ln -s /usr/lib64/libwebp.so /usr/lib64/libwebp.so.4
root@119.10.6.23:~# ls /usr/lib64/libwebp.so.4
/usr/lib64/libwebp.so.4
root@119.10.6.23:~# ls -lart  /usr/lib64/libwebp.so.4
lrwxrwxrwx 1 root root 21 4月  28 10:08 /usr/lib64/libwebp.so.4 -> /usr/lib64/libwebp.so

还缺一堆东西:
yum install libyaml.x86_64
yum install libyaml-devel.x86_64
yum install php-pecl-yaml.x86_64

yum install inotify-tools-devel.x86_64
yum install  boost-python.x86_64
yum install boost-random.x86_64
yum install mysql-libs.x86_64
软件包 boost-1.54.0-9.el6.x86_64.rpm 没有签名
rpm -e  boost-devel-1.41.0-25.el6.centos.x86_64
rpm -e boost-1.41.0-25.el6.centos.x86_64      




———————————————建议centos hhvm使用下面的安装脚本———————————————
这样直接就是最新的了hhvm3.4了
添加epel yum源
rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
安装hhvm所需要的依赖包
yum -y 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 yum源(官方地址被墙)
rpm -Uvh http://blog.linuxeye.com/wp-content/uploads/2014/05/gleez-repo-6-0.el6.noarch.rpm
添加remi yum源
rpm -Uvh http://rpms.famillecollet.com/enterprise/6/remi/x86_64/remi-release-6.5-1.el6.remi.noarch.rpm
从remi安装hhvm依赖包
yum -y --enablerepo=remi install libwebp mysql mysql-devel mysql-lib
安装hhvm
yum -y --nogpgcheck install hhvm
查看hhvm版本号
hhvm --versionHipHop VM 3.4.0-dev+2014.09.29 (rel)Compiler: heads/master-0-gfe70efe4efa8318536ea1d4940362e83e641d905Repo schema: e3bee358a000cf7efe3a0f9642cdc9b488963dcaExtension API: 20140829脚本来自:http://blog.linuxeye.com/


CentOS 7下hhvm Nginx环境搭建:
http://www.linuxeye.com/Linux/2029.html
———————————————————安装步骤—————————————————————————
一、CentOS 6.5 32位安装 HHVM:
安装:
yum -y install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
cd /etc/yum.repos.d
wget http://www.hop5.in/yum/el6/hop5.repo
yum clean all
yum install hhvm
可能遇到的问题:
1.hhvm: error while loading shared libraries: liblcms2.so.2: cannot open shared object file: No such file or directory

yum install http://pkgrepo.linuxtech.net/el6/release/x86_64/liblcms2-2.4-1.el6.x86_64.rpm
2.其他相关文章
http://blog.csdn.net/ownfire/article/details/41366995
http://blog.linuxeye.com/396.html
http://blog.csdn.net/lxlmj/article/details/22283043


二、64位安装HHVM包:
安装hhvm
添加epel yum源

rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
安装hhvm所需要的依赖包

yum -y 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 yum源(官方地址被墙)

rpm -Uvh http://blog.linuxeye.com/wp-content/uploads/2014/05/gleez-repo-6-0.el6.noarch.rpm
添加remi yum源

rpm -Uvh http://rpms.famillecollet.com/enterprise/6/remi/x86_64/remi-release-6.5-1.el6.remi.noarch.rpm
从remi安装hhvm依赖包

yum -y --enablerepo=remi install libwebp mysql mysql-devel mysql-lib
安装hhvm

yum -y --nogpgcheck install hhvm
查看hhvm版本号

hhvm --version
HipHop VM 3.4.0-dev+2014.09.29 (rel)
Compiler: heads/master-0-gfe70efe4efa8318536ea1d4940362e83e641d905
Repo schema: e3bee358a000cf7efe3a0f9642cdc9b488963dca
Extension API: 20140829
3. 配置hhvm
删除安装hhvm时创建的nginx用户

userdel -r nginx
修改hhvm目录权限为www

chown -R www.www /var/run/hhvm
chown -R www.www /var/log/hhvm
修改/usr/local/nginx/conf/nginx.conf使其中一段成为如下:

        location ~ .*\.(php|php5)?$  {
                fastcgi_pass   unix:/var/run/hhvm/sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include        fastcgi_params;
                }
service nginx reload
下载支持hhvm方式添加虚拟主机脚本 vhost_hhvm.sh

cd lnmp
wget http://blog.linuxeye.com/wp-content/uploads/2014/05/vhost_hhvm.sh
chmod +x vhost_hhvm.sh
配置hhvm修改/etc/hhvm/config.hdf,保持如下:

ResourceLimit {
  CoreFileSize = 0          # in bytes
  MaxSocket = 10000         # must be not 0, otherwise HHVM will not start
  SocketDefaultTimeout = 5  # in seconds
  MaxRSS = 0
  MaxRSSPollingCycle = 0    # in seconds, how often to check max memory
  DropCacheCycle = 0        # in seconds, how often to drop disk cache
}

Log {
  Level = Info
  AlwaysLogUnhandledExceptions = true
  RuntimeErrorReportingLevel = 8191
  UseLogFile = true
  UseSyslog = false
  File = /data/logs/hhvm/error.log
  Access {
    * {
      File = /data/logs/hhvm/access.log
      Format = %h %l %u % t \"%r\" %>s %b
    }
  }
}

MySQL {
  ReadOnly = false
  ConnectTimeout = 1000      # in ms
  ReadTimeout = 1000         # in ms
  SlowQueryThreshold = 1000  # in ms, log slow queries as errors
  KillOnTimeout = false
}

Mail {
  SendmailPath = /usr/sbin/sendmail -t -i
  ForceExtraParameters =
}
配置hhvm修改/etc/hhvm/server.ini,使内容保存如下:

; php options
pid = /var/run/hhvm/pid

; hhvm specific
;hhvm.server.port = 9001
hhvm.server.file_socket = /var/run/hhvm/sock
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
修改/etc/hhvm/php.ini,使内容保存如下:

hhvm.mysql.socket = /tmp/mysql.sock ;指定mysql.sock路径(hhvm默认路径sock路径是/var/lib/mysql/mysql.sock)
expose_php = 0 ;关闭头信息X-Powered-By (和hhvm.server.expose_hphp = false作用一样)
memory_limit = 400M
post_max_size = 50M
默认hhvm不提供php中类似disable_functions参数,如何禁用hhvm中shell_exec函数?(可选)
在/etc/hhvm/php.ini中追加如下:

hhvm.jit_enable_rename_function=true
auto_prepend_file= /home/wwwroot/default/disable_functions
新建/home/wwwroot/default/disable_functions,使该文件内容如下:

<?php

function __forbidden_function($name, $obj, $args, $data, &$done) {
  throw new Exception('Calling '.$name.' is forbidden.');
}

fb_intercept('shell_exec', '__forbidden_function');
配置service管理hhvm:

cd /etc/init.d/
rm -rf hhvm #官方默认脚本是以www运行,建议用我修改后的
wget http://blog.linuxeye.com/wp-content/uploads/2014/05/hhvm
chmod +x hhvm
chkconfig hhvm on
service hhvm restart


管理hhvm服务
systemctl enable hhvm #开机自启动
systemctl start hhvm #启动hhvm
systemctl stop hhvm #停止hhvm
systemctl restart hhvm #重启动hhvm
systemctl status hhvm #查看hhvm状态

添加虚拟主机:
vhost_hhvm.sh #和lnmp添加虚拟主机一样
测试wordpress完美运行,且速度非常快;discuz后台正常,前台页面显示有点问题
参考:https://github.com/facebook/hhvm/wiki/HHVM-Pre-built-packages-for-Centos-6.5

安装时,这个rpm包是有很多的依赖:
因为依赖关系问题而跳过的软件包:
    OpenEXR-libs-1.6.1-8.1.el6.x86_64 来自 base
    boost-1.54.0-9.el6.x86_64 来自 gleez
    boost-atomic-1.54.0-9.el6.x86_64 来自 gleez
    boost-chrono-1.54.0-9.el6.x86_64 来自 gleez
    boost-context-1.54.0-9.el6.x86_64 来自 gleez
    boost-date-time-1.54.0-9.el6.x86_64 来自 gleez
    boost-devel-1.54.0-9.el6.x86_64 来自 gleez
    boost-filesystem-1.54.0-9.el6.x86_64 来自 gleez
    boost-graph-1.54.0-9.el6.x86_64 来自 gleez
    boost-iostreams-1.54.0-9.el6.x86_64 来自 gleez
    boost-locale-1.54.0-9.el6.x86_64 来自 gleez
    boost-log-1.54.0-9.el6.x86_64 来自 gleez
    boost-math-1.54.0-9.el6.x86_64 来自 gleez
    boost-program-options-1.54.0-9.el6.x86_64 来自 gleez
    boost-python-1.54.0-9.el6.x86_64 来自 gleez
    boost-random-1.54.0-9.el6.x86_64 来自 gleez
    boost-regex-1.54.0-9.el6.x86_64 来自 gleez
    boost-serialization-1.54.0-9.el6.x86_64 来自 gleez
    boost-signals-1.54.0-9.el6.x86_64 来自 gleez
    boost-system-1.54.0-9.el6.x86_64 来自 gleez
    boost-test-1.54.0-9.el6.x86_64 来自 gleez
    boost-thread-1.54.0-9.el6.x86_64 来自 gleez
    boost-timer-1.54.0-9.el6.x86_64 来自 gleez
    boost-wave-1.54.0-9.el6.x86_64 来自 gleez
    hhvm-3.5.0-4.el6.x86_64 来自 gleez
    ilmbase-1.0.1-6.1.el6.x86_64 来自 base
    inotify-tools-3.14-1.el6.x86_64 来自 epel
    lcms2-2.3-2.el6.x86_64 来自 epel
    libvpx-1.3.0-5.el6_5.x86_64 来自 base
    libyaml-0.1.3-4.el6_6.x86_64 来自 updates


yum install boost-1.54.0-9.el6.x86_64

源码安装:http://tomlog.com/tech/2012/12/21/build-hhvm.html


安装脚本:http://amh.sh/bbs/post-4874-1-1.htm
背景:今天看自己的vps机器的PHP目录下有php -i|grep cookie_path  是session.cookie_path => / => / ,在目录:/usr/local/php/var/session 里有很多session文件,可一看配置: php -i|grep save_path  session.save_path => no value => no value ,于是有一问:
___________________________________________________________________________
session.cookie_path 与session.save_path 有什么区别?
————————————————————————————
有区别
session.save_path 是保存session的路径
session.cookie_path 指定了要session会话 cookie 的有效路径   可查看setcookie第四参数关于cookie有效路径设置相关信息

session ID通过cookie传递时 .. 要创建cookie, session.cookie_path就是设置默认的cookie有效路径

平时的cookie创建如 setcookie ("Test", "12345", time()+3600, "/wwwroot/abc/", ".example.com", 1 ); "/wwwroot/abc/" 就是该cookie只在此路径下有效

由于session创建cookie并没有调用setcookie, 所以创建cookie的所需参数先在ini里的session.cookie .. 进行设置 ..

摘自:http://bbs.phpchina.com/thread-167626-1-1.html

——————————————————————————————————————————————————
后面,我把位置给修改了:
/data/session
session.save_path = "/data/session"

service  php-fpm restart
Gracefully shutting down php-fpm .. done

php -i|grep session.save_path
session.save_path => /data/session => /data/session

背景:深入剖析PHP输入流 php://input ,文章Url:http://www.nowamagic.net/academy/detail/12220520 ,提到ngrep抓包,以前都是tcpdump,这个小工具有点意思,于是查了下,试着安装下Ngrep试一试。

一、使用说明:
如果要分析网络数据包,我们有Wireshark,它有着上千种设定、过滤器以及配置选项。它还有一个命令行版本Tshark。如果只是针对简单的任务,我觉得Wireshark就太重量级了,所以除非我需要更强大的功能,一般情况下就用ngrep来处理了。Ngrep可以让你像类似grep处理文件的方式来处理网络封包。

针对Web流量,你几乎总是想要加上-W byline选项,这会保留换行符,而-q选项可以抑制某些非匹配数据包而产生的输出。下面是一个抓取所有包含有GET或POST请求数据包的例子:

ngrep –q –W byline “^(GET|POST) .*”
你也可以传入附加的报文过滤选项,比如限制匹配的报文只针对某个特定的主机,IP或端口。这里我们把所有流经Google的流量做一个过滤,只针对80端口且报文中包含“search”。

ngrep –q –W byline “search” host www.google.com and port 80

摘处:
http://www.csdn.net/article/2012-11-15/2811906-practical-command-line-tools

二、Solaris安装ngrep:
使用ngrep监控网络接口
  ngrep 是grep(在文本中搜索字符串的工具)的网络版,他力求更多的grep特征,用于搜寻指定的数据包。正由于安装ngrep需用到libpcap库, 所以支持大量的操作系统和网络协议。它当前认可 IPv4/6, TCP, UDP, ICMPv4/6, IGMP和原始交叉以太网, PPP, SLIP, FDDI, 令牌网和空端口,并以与更为普遍的分组过滤工具相同的方式了解BPF过滤逻辑,例如tcpdump和snoop。
  FreeBSD下载和安装:
      #wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/ngrep-1.45-sol10-x86-local.gz
  #gunzip ngrep-1.45-sol10-x86-local.gz
  #pkgadd ngrep-1.45-sol10-x86-local

ngrep的安装就是configure/make/make install 三部曲。
configure时是遇到please wipe out all unused pcap installations
./configure --with-pcap-includes=/usr/local/include/pcap
在安装后输入ngrep来验证下安装是否成功。
  首先看看ngrep的参数,这里只介绍主要选项。
  -q 静默模式,如果没有此开关,未匹配的数据包都以“#”显示
  -e 显示空数据包
  -i 忽略大小写
  -v 反转匹配
  -x 以16进制格式显示
  -X 以16进制格式匹配
  -w 整字匹配
  -p 不使用混杂模式
  -t 在每个匹配的包之前显示时间戳
  -T 显示上一个匹配的数据包之间的时间间隔
  -M 仅进行单行匹配
  -I 从文件中读取数据进行匹配
  -O 将匹配的数据保存到文件
  -n 仅捕获指定数目的数据包进行查看
  -A 匹配到数据包后Dump随后的指定数目的数据包
  -W 设置显示格式byline将解析包中的换行符
  -c 强制显示列的宽度
  -F 使用文件中定义的bpf(Berkeley Packet Filter)
  -N 显示由IANA定义的子协议号
  -d 使用哪个网卡,可以用-L选项查询
  -L 查询网卡接口
  图 6 是没有参数的ngerp的输出界面。
  ngrep命令输出
                                               图6 ngrep命令输出
  下面我们看两个复杂一些的例子,使用命令:
ngrep -qd pcn0 ‘IT专家网’ tcp port 80
  这个命令让ngrep 为TCP报文监控pcn0的80接口,并且只包括“IT专家网”字符串。 这样就可以获得所有该子网中使用访问IT专家网的相关信息。
  另外一个命令:
ngrep -qd pcn0 ‘USER|PASS’ tcp port 21
  这个命令让ngrep 为TCP报文监控pcn0的21接口,并且只包括“user和pass”字符串。我们知道21端口是用来进行FTP连接的端口。 这样就可以获得用于FTP连接的用户名称和密码。

来自:http://security.ctocio.com.cn/tips/30/8196030_4.shtml



三、linux下的ngrep 安装使用:
1  安装libpcap
下载地址   http://www.tcpdump.org/#latest-release
解压                    
tar -zxvf libpcap-1.4.0.tar.gz
进入目录
cd  libpcap-1.4.0
./configure
make
make install

yum install libpcap-devel.x86_64

2  安装ngrep
下载地址
git clone git://git.code.sf.net/p/ngrep/code ngrep-code
Http的:
http://pkgs.fedoraproject.org/repo/pkgs/ngrep/ngrep-code-16ba99a863a89dab25cbf8e9ca410b19a7494c42.zip/a58321bda277a741dc94020a4484bcb6/

进入目录
cd ngrep-code
./configure --with-pcap-includes=/usr/local/include/pcap
make
make install

摘自:http://blog.csdn.net/zljjava/article/details/38046595
        

四、rpm安装:
CentOS:
先用yum install libpcap完全安装libpcap,注意有时候用libpcap安装包安装的不完整会影响ngrep的使用。
如果yum无法安装就用以下步骤安装libpcap
wget http://www.tcpdump.org/release/libpcap-1.3.0.tar.gz
tar -zxf libpcap-1.3.0.tar.gz
cd libpcap-1.3.0
./configure
make && make install

ngrep的安装就是configure/make/make install 三部曲。
configure时是遇到please wipe out all unused pcap installations
./configure --with-pcap-includes=/usr/local/include/pcap
在安装后输入ngrep来验证下安装是否成功。

我也遇到了:
Configuring Network Grep (ngrep) ...
checking for a complete set of pcap headers...
more than one set found in:
/usr/local/include
/usr/local/include/pcap
please wipe out all unused pcap installations
[root@test ngrep-code-16ba99a863a89dab25cbf8e9ca410b19a7494c42]# make

配置时加上路径参数:
./configure --with-pcap-includes=/usr/local/include/pcap
编译:
[root@test ngrep-code-16ba99a863a89dab25cbf8e9ca410b19a7494c42]# make
make  -C regex-0.12 regex.o
make[1]: Entering directory `/home/xiangdong/software/ngrep/ngrep-code-16ba99a863a89dab25cbf8e9ca410b19a7494c42/regex-0.12'
gcc -g  -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1  -I. -I. -c regex.c
make[1]: Leaving directory `/home/xiangdong/software/ngrep/ngrep-code-16ba99a863a89dab25cbf8e9ca410b19a7494c42/regex-0.12'
gcc  -DHAVE_CONFIG_H -DLINUX  -D_BSD_SOURCE=1 -D__FAVOR_BSD=1  -Iregex-0.12 -I/usr/local/include/pcap  -I.  -g -c ngrep.c
gcc  -s -o ngrep ngrep.o  regex-0.12/regex.o -L/usr/local/include/lib -lpcap  
安装:
[root@test ngrep-code-16ba99a863a89dab25cbf8e9ca410b19a7494c42]# make install
./install-sh -c -m 0755 ngrep  //usr/local/bin/ngrep
./install-sh -c -m 0644 ngrep.8 //usr/local/share/man/man8/ngrep.8

安装参考:http://blog.sina.com.cn/s/blog_4d14fb2b01012tqo.html

五、使用方法:
我经常使用的:
ngrep -W byline -d eth0 port 80
捕捉cloudian:18080端口的request和response。-W byline用来解析包中的换行符,否则包里的所有数据都是连续的,可读性差。-d lo是监听本地网卡
ngrep -W byline -d eth0 port 80
捕捉amazon:80端口的request和response。-d eth0 是用来监听对外的网卡

可以用-d any来捕捉所有的包,这个很管用。
ngrep '[a-zA-Z]' -t -W byline -d any tcp port 80


实践如下:



背景:这块明说是HHVM,其实不如说是PHP运行的一个机制及于C实现的一个性能差别及内存占用的对比原因分析。
http://www.csdn.net/article/2014-12-25/2823234

摘录:
对于“弱类型”的批评观点大致如下:

    在“严谨”的语言中,通常是预先定义好一个变量的类型,自始至终,变量的类型是固定的,使用范围也是固定。而PHP的变量,通常我们只能看见它名字,类型大部分都不可以预先定义,并且还可以随意改变。(内存分配不好管理)
    为了兼容弱类型特性,PHP需要实现大量兼容代码,包括类型判断、类型转换、存储方式等,增加了语言内部的复杂度。(执行效率低下)
    变量的类型是不可控的,在执行过程中存在大量的“隐性类型转换”,容易产生不可预知的结果。(这里的确需要强调,PHP的类型转换是个必须掌握的点,各种类型的互相转换的可能会产生很多问题,尤其是初学PHP的同学哈)

他们认为,这些都不符合“所见即所得”的简单性,而语法严谨的语言更高效率,也更容易“理解”。

受到类似批评的还有Javascript等语言,因为它在这个问题上的表现是一样的。但是,一门语言最终被大规模使用,必然有它们的道理。PHP成为Web服务开发的首选脚本语言,Javascript则直接称霸Web前端领域,能走到这一步都不可能是偶然因素,开发者们用脚投票选择了它们。编程语言是人类和机器沟通的桥梁,终极追求是实现“人人皆可编程”的宏伟目标。

——————————————————————————————————————————————————————————————————————————
http://liuzhichao.com/p/1909.html
背景:有时候用户输入了email,xxx@xxxxx.com,这个xxxxx.com是否真有A记录,MX 记录也就是说是否真有这个邮件提供商,怎么用PHP函数知道呢?checkdnsrr函数就知道,如下两种用法:
一、php验证用户输入的邮箱有效性和正确性,用checkdnsrr验证email的域名部分的有效性:

注意:checkdnsrr函数在win主机上是无效的!下面是国外某程序员提出的一种解决办法,另外写了个函数代替checkdnsrr函数:

摘自:http://www.educity.cn/develop/406028.html
二、checkdnsrr -- 根据一个给定的host name(域名)或者IP地址检查它是否有DNS记录,其实也就是检验它是否存在。
checkdnsrr — Check DNS records corresponding to a given Internet host name or IP address
译文: checkdnsrr -- 根据一个给定的host name(域名)或者IP地址检查它是否有DNS记录,其实也就是检验它是否存在。
Note:  This function is now available on Windows platforms.
注意:该函数在windows平台不支持
我试了一下,果然,提示没有这个函数。
下面是一个hack的方法,这样,我们在windows上做开发时,也能看到效果了!

接下来我来介绍一下参数:
    bool checkdnsrr ( string $host [, string $type = "MX" ] )
    第一个参数我们就不说了,就是域名或者ip
    第二个参数是解析类型,分别有:
    A (Address) 记录     是指定主机名(或域名)对应的IP地址记录。
    MX 记录              是指定邮件交换记录(默认)
    NS 记录              是指定域名服务器的记录,指定该域名由哪个DNS来进行解析。
    SOA记录              一般在辅助的dns服务器里才用到,用来指定谁是主服务器。
    PTR记录              从ip指向域名的反向解析记录
    CNAME记录            别名记录
    AAAA记录             是一个指向IPv6的记录
    A6记录               同上
    SRV记录              它是DNS服务器的数据库中支持的一种资源记录的类型,一般是为Microsoft的活动目录设置时的应用。
    TXT记录              文本信息
    ANY记录              任何记录,所有数据类型
这个函数常被我们用于检测email是否真实存在!
摘自:http://blog.sina.com.cn/s/blog_4ce89f200100uk74.html
阅读全文
背景:安装一个破解版的Zend Studio 12.0.1后,发现PHP内置函数出现警告,按http://www.geekso.com/ZendStudioCodeAutocomplete/ 处理后也不行,于是:
**
在用 Zend Studio 编写 PHP 项目时发现调用系统函数时调试正常, 但是在编写代码时却提示函数未定义"Call to undefined function ", 在左侧语法检测状态区域栏总是显示个小黄色的三角形的感叹号. **'

解决办法:

1, 修改项目 .buildpath 文件

<?xml version="1.0" encoding="UTF-8"?> <buildpath> <buildpathentry kind="src" path=""/> <buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/># 新增一句 kind="con" </buildpath>

2, 重置项目编译状态

Project -> Clean -> Clean all projects

3, 重新编译项目

Project -> Build All

4, 完成! 再看看是不是小黄色的感冒号图标消失啦~

提醒: PHP Language Library 中存放的都是一些系统函数以及扩展库函数的定义原型, 当编码时调用这些函数时 Zend Studio 可以根据这些定义原型进行代码提示及补全.

最后,通过 zend studio 菜单 帮助 >> welcome 安装高版本的PHP, 可以得到支持.
Zend Studio 12.0.1默认是没有一个PHP版本的,得添加后才能支持到PHP内置函数不警告。

实践上都没有搞定:什么把PHP各个版本给加在welcome页面上选上apply啊,我把原来的样式和workspace-》defaultworkspace给删除干净后,重新指向这个地方,导入:Zend Studio 10.5.0 首选项配置文件-2014-01-07.epf 后,把前面的项目给重新建立项目,于是不警告了,好了。
参考:
http://segmentfault.com/blog/fengxiuping/1190000000449206
http://bbs.itcast.cn/thread-7244-1-1.html
背景:i++还是++i这个问题,我为什么记下了,又忘记了,我觉得这是一个哲学问题。
这是一个医学问题,这是一个物理问题:

Firefox下,打开一个空白页面,按下:Shift+F4,调出Js调试工具:


先后是:
1
2
2
2
原因如下:
a= i++;
则相当于  a=i;i=i+1;   //alert i++ 时:相当于a=i,还是原值1。后面再alerti时相当于i=i+1了等于2.
a=++i;
则相当于  i=i+1;a=i;// alert ++i 时,相当于前面的i=i+1,所以就等于2了,而接着再alert i 时还是2.
________________________________________________________
都是i=i+1的意思,区别在于i++是i先不自加,在语句完后自加,++i先自加;
列如a=1+i++;i本来为1的话,这里a=1+1;语句完后i才加1为2;
a=1+++i的话就先i=i+1;i=2.然后a=i+1,a=3

直接使用看不出区别,都是变量i加1
在赋值时才能进行区别,
如:
y=i++  // y的值为i (先引用,后运算)
y=++i  // y的值为i+1的结果 (先运算,后引用)

++i是在使用i之前先使i的值加1
i++是在使用i之后,使i的值加1
背景:用PHP做一些简单的上传是没有任何的问题,但是要做断点上传好像也是没有大问题,但要是并发的切片加断点上传可能就会有问题了哟。
第一个问题是合并问题:如果一上传就合并,PHP老半天不返回是一个方面(是PHP超时还是Nginx超时?),这样势必会造成客户端因没返回,没法再启动新的上传进程,如果用php的追加写文件内存太大还会退出的可能,用上gearmand后出现异步同时写,可能加快了传输效率的同时IO可能会比较密集(假如同一时间并发上传的人多的情况。)。
第二个问题是先后问题:如果并发时出现了传一半时最后一片先上传上来了怎么办?如果直接追加进文件是会不按顺序出错的,如果放在那儿不管,那啥时候管,这也是一个问题。
第三个问题是锁的问题:并发时如果同时两片到了,像PHP这种如何去结合锁的功能呢?据我所知有memcache的add函数是原子操作,可以利用,那就设计到锁多久,是不是又回到第一个问题,返回时间得浪费多长时间呢。
基于上面三点,看来PHP做这活不是太靠谱,于是引出了gearman这个模型,相当于异步处理,再集合PHP的memcache锁(memcache放内存,可能得用ttserver才行,协议一样的。),PHP上传逻辑处理,Nginx上传插件,才有可能做一个较为靠谱且稳定的分片,断点加多进程(多线程)上传服务搭建。

一、从源码安装gearmand遇到的各种外部代码版本及yum版本太低的导致各种编译不过的问题,历程相当的麻烦,特别是boost和这个libevent默认的yum install非常低,都给编译了,把rpm所强制删除了,最后才成功,再就是g++编译版本,得export后才能编译,否则一堆问题,都在下面有描写。
出现第一个问题及处理办法:
libgearman-server/plugins/queue/sqlite/instance.cc: In member function 'bool gearmand::queue::Instance::_sqlite_prepare(const std::string&, sqlite3_stmt**)':
libgearman-server/plugins/queue/sqlite/instance.cc:125: error: 'sqlite3_prepare_v2' was not declared in this scope
libgearman-server/plugins/queue/sqlite/instance.cc: In member function 'gearmand_error_t gearmand::queue::Instance::init()':
libgearman-server/plugins/queue/sqlite/instance.cc:224: error: 'SQLITE_OPEN_READWRITE' was not declared in this scope
libgearman-server/plugins/queue/sqlite/instance.cc:224: error: 'SQLITE_OPEN_CREATE' was not declared in this scope
libgearman-server/plugins/queue/sqlite/instance.cc:224: error: 'sqlite3_open_v2' was not declared in this scope
make[1]: *** [libgearman-server/plugins/queue/sqlite/libgearman_server_libgearman_server_la-instance.lo] Error 1
将队列存放在sqlite3或postgresql。这货是用的sqlite存队列啊:
yum search sqlite
yum install sqlite.x86_64 sqlite-devel.x86_64
还是不行,参考:
安装:https://jackxiang.com/post/7709/ 后,
最后在编译Gearman时带上 --with-sqlite3=/usr/local/sqlite3,告诉编译器应该使用这个新的sqlite即可。


出现第二个问题及处理办法:
./libgearman-1.0/gearman.h:53:23: error: cinttypes: No such file or directory
命令:
yum install gcc44 gcc44-c++ libstdc++44-devel -y
然后在环境变量里加入:
export CC=/usr/bin/gcc44 or export CC=/usr/bin/gcc
export CXX=/usr/bin/g++44
保存退出后执行:
source /etc/profile
删除gearmand-0.34文件夹重新进行编译.
重新进行编译后执行make这步......

看来还得重新export一次新的编译器,因为昨天的关了终端,今天的又没了:
export CC=/usr/bin/gcc44 or export CC=/usr/bin/gcc  //这行有问题~
export CXX=/usr/bin/g++44
g++ -o testmemcached testmemcached.cpp -lmemcached
为何还是不行?
echo $CC
/usr/bin/gcc  //没变,这儿有问题,再重新设置一次,查到上面这个or有问题:export CC=/usr/bin/gcc44。
# echo $CXX
/usr/bin/g++44 //变了

重新设置,好了:
export CC=/usr/bin/gcc44
/usr/bin/gcc44

在后面有详细的说明,可以不source直接设置环境变量,因为编译后也不一定要这个版本的gcc的。



出现第三个问题的处理办法:
ibgearman-server/plugins/queue/mysql/queue.cc:430: error: 'mysql_error' was not declared in this scope
libgearman-server/plugins/queue/mysql/queue.cc: In function 'gearmand_error_t _mysql_queue_replay(gearman_server_st*, void*, gearmand_error_t (*)(gearman_server_st*, void*, const char*, size_t, const char*, size_t, const void*, size_t, gearman_job_priority_t, int64_t), void*)':
libgearman-server/plugins/queue/mysql/queue.cc:446: error: 'MYSQL_RES' was not declared in this scope
libgearman-server/plugins/queue/mysql/queue.cc:446: error: 'result' was not declared in this scope
libgearman-server/plugins/queue/mysql/queue.cc:447: error: 'MYSQL_ROW' was not declared in this scope

[root@test gearmand-1.1.12]# ./configure --help|grep mysql
  --with-mysql=[ARG]      use MySQL client library [default=yes], optionally
                          specify path to mysql_config
              Full path to mysql_config program

看样子是想用mysql做队列queue的:


加上还是报错,去了得了,不用mysql做队列,有sqlite足够了,
--without-mysql就好了,来自:
https://bugs.launchpad.net/gearmand/+bug/1327038 说的:


出现第四个问题的解决办法:
/home/xiangdong/software/gearmand-1.1.12/bin/gearadmin.cc:129: undefined reference to `boost::program_options::options_description::m_default_line_length'
/home/xiangdong/software/gearmand-1.1.12/bin/gearadmin.cc:129: undefined reference to `boost::program_options::options_description::options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)'
bin/gearadmin.o: In function `boost::program_options::basic_command_line_parser<char>::run()':
/usr/local/include/boost/program_options/detail/parsers.hpp:107: undefined reference to `boost::program_options::detail::cmdline::get_canonical_option_prefix()'
bin/gearadmin.o: In function `boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>)':
/usr/local/include/boost/program_options/detail/parsers.hpp:77: undefined reference to `boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>)'
collect2: ld returned 1 exit status
make[1]: *** [bin/gearadmin] Error 1
make[1]: Leaving directory `/home/xiangdong/software/gearmand-1.1.12'


[root@test gearmand-1.1.12]# ./configure --help|grep boost
  --with-boost[=ARG]      use Boost library from a standard location
  --with-boost-libdir=LIB_DIR
                          Force given directory for boost libraries. Note that
                          fails and you know exactly where your boost
  --with-boost-program-options[=special-lib]
                          use the program options library from boost - it is
                          --with-boost-program-options=boost_program_options-gcc-mt-1_33_1

指定boost的库:
从这儿得知在这儿呢:  http://jackxiang.com/post/7706/
系统默认会将include拷贝到/usr/local/include/boost/中
将lib拷贝到/usr/local/lib下
yum install boost-devel  [实践失败]
回头了解下boost的结构,rpm包是啥样的,如下所示,版本号1.33,有可能是因为lddconfig里默认配置指向这个旧版本了,如下:
vi /etc/ld.so.conf


[root@test ~]# rpm -ql boost-1.33.1-16.el5_9
/usr/lib64/*.so.*  //各种so文件
/usr/lib/*.so.*     //各种so文件
rpm -ql boost-devel-1.33.1-16.el5_9
/usr/include/boost  里面是各种分类目录,里面是hpp头文件
algorithm/
archive/
assign/
bind/
compatibility
config/
devel包里还有静态a文件及动态so文件:
/usr/lib/libboost_test_exec_monitor.a
/usr/lib/libboost_test_exec_monitor.so

如下实践试试:
cd /home/xiangdong/software/boost_1_57_0
./bootstrap.sh --prefix=/usr/local/boost-1.57
vi tools/build/v2/user-config.jam
文件尾部增加(没找到,直接./b2 ./b2 install 即可!):
using mpi  
./b2
./b2 install


Boost headers version >= 1.39.0
[root@localdomain gearmand-1.1.12]# yum search boost
[root@localdomain gearmand-1.1.12]# yum install boost.x86_64
[root@localdomain gearmand-1.1.12]# yum install yum install boost-devel.x86_64
旧的yum源,直接干死,用源码装个试试:



出现第五个问题的解决办法:
/home/xiangdong/software/gearmand-1.1.12/libgearman-server/gearmand_con.cc:677: undefined reference to `event_initialized'
collect2: ld returned 1 exit status
libevent版本太老了,更新新的版本:
安装最新版本的libevent,并执行以下操作:(备份老版本的/usr/lib64/libevent.so)
ln -s /usr/lib64/libevent-2.0.so.5 /usr/lib64/libevent.so
删除老旧的libevent的rpm包后,安装最新的方法实践如下:
[root@test software]# cp  /usr/lib64/libevent.so /usr/lib64/libevent.so.bak.old
[root@test libevent-2.0.21-stable]# tar -zxvf libevent-2.0.21-stable.tar.gz
[root@test libevent-2.0.21-stable]# cd libevent-2.0.21-stable
[root@test libevent-2.0.21-stable]# ./configure --prefix=/usr/local/libevent-2.0.21-stable


ls -al /usr/lib | grep libevent
rpm -qa|grep libevent
libevent-1.4.13-1
libevent-devel-1.4.13-1
libevent-devel-1.4.13-1
libevent-1.4.13-1

rpm -e --allmatches --nodeps libevent-1.4.13-1 libevent-devel-1.4.13-1
[root@test libevent-2.0.21-stable]# rpm -e --allmatches --nodeps libevent-1.4.13-1 libevent-devel-1.4.13-1
[root@test libevent-2.0.21-stable]#

卸载后看还有没:
[root@test libevent-2.0.21-stable]# ls -al /usr/lib | grep libevent  
lrwxrwxrwx   1 root root       31 Dec 30 17:17 libevent-1.1a.so.1 -> /usr/lib/libevent-1.1a.so.1.0.2
-rw-r--r--   1 root root    31596 Jan  7  2007 libevent-1.1a.so.1.0.2

rm -Rf  /usr/lib/libevent-1.1a.so.1.0.2 /usr/lib/libevent-1.1a.so.1 //删除干净
[root@test libevent-2.0.21-stable]# rm -Rf  /usr/lib/libevent-1.1a.so.1.0.2 /usr/lib/libevent-1.1a.so.1
[root@test libevent-2.0.21-stable]#

cd /home/xiangdong/software/libevent-2.0.21-stable  //最新安装包
./configure --prefix=/usr   //libevent会安装到 /usr/lib 或 /usr/local/lib 下
#./configure --prefix=/usr/local/libevent-2.0.21-stable
[root@test libevent-2.0.21-stable]# ./configure --prefix=/usr && make && make install
测试libevent是否安装成功:ls -al /usr/lib | grep libevent(或 ls -al /usr/local/lib | grep libevent)
ls -al /usr/lib | grep libevent
lrwxrwxrwx   1 root root       21 Dec 31 09:44 libevent-2.0.so.5 -> libevent-2.0.so.5.1.9
-rwxr-xr-x   1 root root  1065819 Dec 31 09:44 libevent-2.0.so.5.1.9
-rw-r--r--   1 root root  1678970 Dec 31 09:44 libevent.a
lrwxrwxrwx   1 root root       26 Dec 31 09:44 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.9

如果libevent的安装目录为/usr/local/lib下,则还需要建立 libevent-1.4.so.2 到 /usr/lib 的软连接,这样其他程序运行时才能找到libevent库:ln -s /usr/local/lib/libevent-1.4.so.2  /usr/lib/libevent-1.4.so.2

ls /usr/lib/libevent-2.0.so.5
/usr/lib/libevent-2.0.so.5

干掉旧的libevent的残留的动态so文件:
ls -al /usr/lib64 | grep libevent
lrwxrwxrwx   1 root root       19 Dec 31 09:40 libevent-1.4.so.2 -> libevent.so.bak.old
-rwxr-xr-x   1 root root   104296 Dec 31 09:22 libevent.so.bak.old
[root@test libevent-2.0.21-stable]# rm -Rf /usr/lib64/libevent-1.4.so.2
参考来自:http://blog.sina.com.cn/s/blog_4b93170a0100mbm9.html

编译成功结果如下:


启动gearmand的方法:
[root@test gearmand-1.1.12]# whereis gearmand
gearmand: /usr/local/sbin/gearmand
[root@test ~]# mkdir -p /usr/local/gearman/log

ls /usr/local/sqlite3/bin/
sqlite3

*特别提醒,(mysql性能上可能在做队列上并不比sqlite强到哪儿去)
使用sqlite更加简单方便 :
/usr/local/sbin/gearmand -l /usr/local/gearman/log/trace2.log --verbose INFO -p 4830 -q libsqlite3 --libsqlite3-db /usr/local/sqlite/bin/gearman --libsqlite3-table gearman_queue -d
很遗憾,我到现在也没能编译出对MySQL的持久化

[root@test ~]# /usr/local/sbin/gearmand -l /usr/local/gearman/log/trace2.log --verbose INFO -p 4830 -q libsqlite3 --libsqlite3-db /usr/local/sqlite/bin/gearman --libsqlite3-table gearman_queue -d
/usr/local/sbin/gearmand: Error while initializing the queue : libsqlite3

原来是sqlite的位置不对,修改路径后就OK了:

启动成功:
[root@test sqlite3]# /usr/local/sbin/gearmand -l /usr/local/gearman/log/trace2.log --verbose INFO -p 4830 -q libsqlite3 --libsqlite3-db /usr/local/sqlite3/bin/gearman --libsqlite3-table gearman_queue -d
[root@test sqlite3]#
端口存在了,说明是真的启动成功了:
[root@test sqlite3]# netstat -atlunp|grep 4830
tcp        0      0 0.0.0.0:4830                0.0.0.0:*                   LISTEN      17820/gearmand      
tcp        0      0 :::4830                     :::*                        LISTEN      17820/gearmand  

也就是说gearmand启动时候自己建立一个sqlite的表,如下:
[root@test sqlite3]# cat /usr/local/sqlite3/bin/gearman
SQLite format 3@  ''blegearman_queuegearman_queueCREATE TABLE gearman_queue ( unique_key TEXT, function_name TEXT, priority INTEGER, data BLOB, when_to_run INTEGER, PRIMARY KEY (unique_key, function_name))9M'indexsqlite_autoindex_gearman_queue_1gearman_queue

经过一陈折腾,说明这个gearmand对boost库的要求高,对libevent的版本也要求高,不是能经过yum install能解决得了的,得自己安装后指定,再就是对编译器的版本也是有要求的,也就是说相对来说其安装比较苛刻一些,如Lamp架构相比较的话,难度要高一些。
——————————————————————————————————————————————————————————————
总之,一大堆问题,这货居然还这么流行听说Gearman最初用于LiveJournal的图片resize功能,由于图片resize需要消耗大量计算资 源,因此需要调度到后端多台服务器执行,完成任务之后返回前端再呈现到界面。,看来广大分发系统还真得靠它啊,其它各种小问题不断,参考:
http://www.111cn.net/sys/CentOS/65334.htm

二、PHP的gearmand扩展编译及遇到问题解决实践如下:
PHP的gearmand折腾扩展,这块试了好几个版本的扩展要么configure不过去,要么是lib里却啥,但最后还是以当前最新的版本gearman-1.1.2.tgz给解决了:

./configure --with-php-config=/usr/local/php/bin/php-config
出现如下所示的配置错误:
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable gearman support... yes, shared
found in /usr/local
checking for gearman_create in -lgearman... no
configure: error: wrong libgearman version or lib not found

问题一:
gearman的PHP扩展时出现configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.警告信息。
警告信息说明需要安装 re2c
执行下面命令安装:
wget http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
2014-12-31 11:01:59 (999 KB/s) - `re2c-0.13.5.tar.gz' saved [782725/782725]
tar -zxvf re2c-0.13.5.tar.gz
cd re2c-0.13.5
./configure && make && make install //安装成功,警告得到了解决,第二个依旧存在。
它的意思是好像没有找到lib,不对是找到了没有找到里面的某个叫gearman_create的函数,这个就奇怪了,找下:
[root@test /]# find . -name "*gearman*.so*"
./usr/local/lib/libgearman.so.8.0.0
./usr/local/lib/libgearman.so
./usr/local/lib/libgearman.so.8

[root@test /]# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/lib
/lib64
/usr/lib                                                                                                                                                                                            
/usr/lib64
/usr/local/lib
/usr/local/lib
有这个位置的啊。
[root@test /]# ldconfig  //重新lib的位置载入。

[root@test gearman-0.4.0]# phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
[root@test gearman-0.4.0]# ./configure --with-php-config=/usr/local/php/bin/php-config

问题依旧,去官网看一下呗,http://gearman.org/download/:
文字摘录:PHP
There are two PHP client/worker libraries, one which is a pure PHP extension and one which wraps the libgearman C library.
Gearman Extension
A PHP extension that wraps the libgearman C library.
Gearman PHP Extension (1.0.2) (Source)
官方的PHP扩展高V1.0.2,我这个是gearman-0.4.0太旧了,好像还有更高的gearman-1.1.2.tgz,http://pecl.php.net/package/gearman,放上官网这个上去重新试下了:
tar -zxvf gearman-1.0.2.tgz
cd gearman-1.0.2
[root@test gearman-1.0.2]# phpize
./configure --with-php-config=/usr/local/php/bin/php-config   //这个没有问题
[root@test gearman-1.0.2]# make && make install
/home/xiangdong/software/gearman-1.0.2/php_gearman.c: In function ‘zm_startup_gearman’:
/home/xiangdong/software/gearman-1.0.2/php_gearman.c:4638: error: ‘GEARMAN_MAGIC_TEXT’ undeclared (first use in this function)
/home/xiangdong/software/gearman-1.0.2/php_gearman.c:4638: error: (Each undeclared identifier is reported only once
还是差啥么子玩意,换个更新的看下,gearman-1.1.2.tgz 实践OK了,如下:
Libraries have been installed in:
   /home/xiangdong/software/gearman-1.1.2/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

[root@test gearman-1.1.2]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
真在的:
ls  /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/gearman.so
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/gearman.so
在php.ini里加上这个扩展就成了。Successful....EOF


[root@test gearman-1.1.2]# php -v
PHP 5.3.10 (cli) (built: Feb  3 2012 14:04:56)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator

[root@test gearman-1.1.2]# vi /usr/local/php/etc/php.ini
extension = "gearman.so"  

[root@test gearman-1.1.2]# php -m|grep gearman
gearman



三、代码编写task的分发及client的及简单代码实践OK及其情况实践Ok:
cd /usr/local/gearman/
[root@test gearman]# mkdir codesTest
[root@test gearman]# cd codesTest/
[root@test codesTest]# vi myworker.php


以守护进程方式启动worker:
# nohup php myworker.php >/dev/null 2>&1 &
[root@test codesTest]# nohup php myworker.php >/dev/null 2>&1 &
[1] 31238

一个发送任务处理请求的client:
vi  myclient.php
[root@test codesTest]# vi  myclient.php


运行myclient.php:
[root@test codesTest]# php myclient.php "Jose"
hello, Jose
H:test.local:2

一个发出并行处理任务请求的例子tasksclient:
[root@test codesTest]# vi  tasksclient.php


运行tasksclient:
[root@test codesTest]# php tasksclient.php
Completed task:: id :2 , handled result:hello, John
Completed task:: id :1 , handled result:hello, Jose

查看worker及队列情况:
(echo "workers"; sleep 0.1) | nc 192.168.109.8 4830
[root@test codesTest]#  (echo "workers"; sleep 0.1) | nc 192.168.109.8 4830
34 192.168.109.8 - : sayhello logMsg
35 192.168.109.8 - :
.
查看当前队列情况(显示格式FUNCTION\tTOTAL\tRUNNING\tAVAILABLE_WORKERS):
(echo "status"; sleep 0.1) | nc 192.168.109.8 4830
[root@test codesTest]# (echo "status"; sleep 0.1) | nc 192.168.109.8 4830
sayhello        0       0       1
logMsg  0       0       1
.

监控php的守护进程(没实践), 可以开多个,并同时监控:
关于Worker守护进程的启动和监控
上面例子中直接启动worker脚本作为守护进程,无法监控到worker进程是否存活.
使用Unix进程监控supervisord则可轻松解决这个问题.
将如下配置添加到supervisord的配置中,即可实现由supervisord来启动和监控myworker.
编辑配置文件 vi /etc/supervisord.conf
[program:myworker]
command=/usr/local/php5415/bin/php myworker.php
process_name=%(program_name)s_%(process_num)02d
;修改numprocs即可同时开启多个worker进程
numprocs=1
directory=/usr/local/gearman/codesTest
autostart=true
autorestart=true
user=gearmand
stopsignal=KILL
Posted in Daemon / Worker, Gearman.
Tagged gearman.

监控这块看:
http://jingyan.baidu.com/article/375c8e198d1b1425f2a2290c.html

上面这块的PHP扩展代码及实践来自:
http://www.51itstudy.com/30114.html
http://codego.net/384693/

_________下面是摘录别的文章不一定自己配置时可完全过得过,得按自己环境作配置安装,只是用作参考!_______
Gearman的目的在于用PHP扩展分发,于是PHP扩展如何安装:
tar zxvf gearman-1.1.1.tgz
cd gearman-1.1.1
/opt/local/php/bin/phpize
./configure --with-php-config=/opt/local/php/bin/php-config --with-gearman
make
make install
编辑 php.ini
vi php.ini
增加
extension = "gearman.so"
重启php

启动gearmand 服务
gearmand -L 10.6.0.6 -p 4730  -u root -l /var/log/gearmand.log -d
其他参数请  gearmand --help

摘自:http://jicki.blog.51cto.com/1323993/1177487
阅读全文
背景:用Nginx上传插件实现大文件分片上传后,处理子程序的程序需要每次对分片进行合并,但又不想耗费PHP太多内存,只好让shell来干这事儿,同时呢,又不想让PHP用exec合并文件时出现等待,怎么办?

   在php中,如果出现exec();那么php是先运行完exec中的外部命令,然后继续执行接下来的php语句的。有什么办法让exec自己在那运行,php语句不等待,自己运行下去,让浏览器不用等待。谢谢。

Note:
如何程序使用此函数启动,为了能保持在后台运行,此程序必须将输出重定向到文件或其它输出流。 否则会导致 PHP 挂起,直至程序执行结束。
exec("命令 > null");

来自:http://zhidao.baidu.com/link?url=sqz2GSYfd3fJWE5F7F_2AR15zpj6VNe-9jc1pMNmmj-3MB5KHOnbzOB_9Dls43TqL1zH0PZmdZuN1AXSc_Xj-_

——————————————————————————————————————————————————————————————
请问在php程序里如何非阻塞地执行另一个.php脚本?

我们知道在命令行里可以用php XX.php调用一个php脚本,
但是在php程序里怎样调用另一个.php脚本呢?
要求有两个:
(1) 非阻塞式的。即主程序执行调用其他脚本的语句后,继续执行下面的语句而不阻塞。
(2) 能否把一些主程序的对象作为参数传给被调用的脚本?可以以变通的方式。

exec("php XX.php")函数貌似不行,因为exec()是阻塞的。
请大家想想办法,如何满足以上这两个解决问题?谢谢!


刚看了看Process Control Functions的说明(英文的没看太明白).不过看到了pcntl_fork()复制进程.
这个和Perl的fork()差不多能实现.不过Process Control Functions不能在windows下使用啊,只能在unix或linux下用.比较不爽啊!!!!!
示範 1.pcntl_fork() example

主进程执行当前程序,让子进程去调用另一个php脚本吧,这不就不阻塞了吗!!!


来自:http://bbs.phpchina.com/thread-23687-1-1.html


当PHP作为后端处理需要完成一些长时间处理,为了快速响应页面请求,不作结果返回判断的情况下,可以有如下措施:

一、若你使用的是FastCGI模式,使用fastcgi_finish_request()能马上结束会话,但PHP线程继续在跑。

这个例子输出结果可看到输出program start.后会话就返回了,所以debug那个输出浏览器是接收不到的,而log.txt文件能完整接收到三个完成时间。

二、使用fsockopen的非阻塞模式请求另外的网址

三、使用Gearman
Gearman是一个具有php扩展的分布式异步处理框架,能处理大批量异步任务。
摘自:http://blog.4wer.com/php-nonblock
PHP中实现非阻塞模式:
http://blog.csdn.net/linvo/article/details/5466046
背景:项目之前是在jsp下,现在想切换成php,如何在nginx中配置运行无扩展名的php文件,或运行不是.php扩展名的文件呢?本文为大家介绍的方法,你可以参考下。
根据下面实践好像不行,出现403:"GET /ICU_UP/clientupload.jsp HTTP/1.0" 403 35
于是修改成urlrewrite格式,如下:


/ICU_UP/clientupload.jsp
转写成:
/ICU_UP/clientupload.php

阅读全文
扩展编译好用,通过php编码测试报“段错误",如果是c语言都是用gdb进行设置,那php扩展要如何进行调试呢?搜索了下,虽然是php扩展但是core是php 的core不是单个so扩展的coredump
这里使用ulimit -c unlimited来开启core文件,使用gdb来对core文件进行调试演示一下。
阅读全文
背景:cache有多台,addServer,这块里有一个算法不是太好,在腾讯时在做云存储时有兄弟改成了环形算法,更能最大限度的在添加机器后影响小,这块我目前没几台机器没有这个必要,自己写还不如这位兄弟写的,特转。
阅读全文
背景:大文件的断点续传,有时网络波动啥的,需要断点从已经下载位置续传下载文件,对于没有传过的文件再次从开始下载就麻烦了,这块http协议支持的,Apache和Nginx都支持这样的方法实现了从某个部分进行断点下载。
服务器是否支持断点续传的判断:
更多 0
断点续传 linux wget 服务器 curl
通常情况下,Web服务器(如Apache)会默认开启对断点续传的支持。因此,如果直接通过Web服务器来提供文件的下载,可以不必做特别的配置,即可享受到断点续传的好处。断点续传是在发起HTTP请求的时候加入RANGE头来告诉服务器客户端已经下载了多少字节。等所有这些请求都返回之后,再把得到的内容一块一块的拼接起来得到完整的资源。

Resumable download file Web服务器(如Apache)默认开启断点续传

你可以通过以下的命令来测试一下。

Linux 测试服务器是否支持断点续传

localhost [~]# wget -S http://httpd.apache.org/images/httpd_logo_wide_new.png 2>&1 | grep ‘Accept-Ranges’
  Accept-Ranges: bytes

输出结果 Accept-Ranges: bytes ,说明服务器支持按字节下载。

curl 命令发送字节范围下载

curl –range 0-99 http://images.apple.com/home/images/billboard_iphone_hero.jpg

这样可以到最开始99字节,结果如下图:

curl range bytes request curl 命令发送字节范围请求

说明从服务器端按字节范围下载是完全没有问题的。

现在我们尝试以下方式:

1、一次性下载整个图片。

localhost [~]# curl –range 0-98315 http://images.apple.com/home/images/billboard_iphone_hero.jpg > test.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 98316  100 98316    0     0   524k      0 –:–:– –:–:– –:—:—  527k

完成后,test.jpg完全等于billboard_iphone_hero.jpg,文件大小为98,316 字节。

实践如下:我的Nginx服务器,请求下看是否支持,如下:
1)实践下下载这块的header返回头有Accept-Ranges: bytes证明Nginx也是支持断点续传下载的:



(1)Curl包含range的请求头是这样的:

(2)其抓包Nginx的返回头是这样:
HTTP/1.1 206 Partial Content
Server: nginx
Date: Wed, 19 Nov 2014 14:45:07 GMT
Content-Type: image/jpeg
Content-Length: 109
Last-Modified: Fri, 07 Nov 2014 05:06:12 GMT
Connection: keep-alive
ETag: "545c5344-1b8c"
Expires: Fri, 19 Dec 2014 14:45:07 GMT
Cache-Control: max-age=2592000
Content-Range: bytes 0-108/7052


4)通过前面的curl及wget联合起来,先后组合起来实现一个断点下载整个图片,并看其服务器返回头(curl已经下了前面的108,后从109开始wget:
(1)先保存一部分到108:


(2)再通过wget的断点续传下载命令-c,请求剩下的部分(Content-Range: bytes 109-7051/7052):
A)加上-S看返回头, -S,  --server-response         打印服务器响应。:


B)发起头如下,也就是说经curl保存一部分后,wget通过-c参数时,后面它会去读取目前文件大小,后写在http头里去找服务端要,请求头如下:


注意:字节是从0开始,结束字节为总字节长度 减 1。
来自:http://ju.outofmemory.cn/entry/23646
Nginx:http://chenzhenianqing.cn/articles/926.html
阅读全文
分页: 9/26 第一页 上页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 下页 最后页 [ 显示模式: 摘要 | 列表 ]