日常会遇到的问题
- 函数的任意数目的参数
你可能知道PHP允许你定义一个默认参数的函数。但你可能并不知道PHP还允许你定义一个完全任意的参数的函数
function foo() {
// 取得所有的传入参数的数组
$args = func_get_args();
foreach ($args as $k => $v) {
echo "arg".($k+1).": $v\n";
}
}
foo();
/* 什么也不会输出 */
foo('hello');
/* 输出
arg1: hello
*/
foo('hello', 'world', 'again');
/* 输出
arg1: hello
arg2: world
arg3: again
*/
- 生成唯一的ID
// 前缀
echo uniqid('foo_');
/* 输出
foo_4bd67d6cd8b8f
*/
// 有更多的熵
echo uniqid('',true);
/* 输出
4bd67d6cd8b926.12135106
*/
// 都有
echo uniqid('bar_',true);
/* 输出
bar_4bd67da367b650.43684647
*/
apache路由重写
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^/index_wx.php/
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=permanent,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^(/index_wx.php|/do.php)
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=permanent,L]
比如apache环境中,在原网站的.htaccess中加入
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
将非443端口的访问全部跳转到443(https)
案例说明
https://www.zh30.com/centos-apache-https-ssl.html
http://www.cnblogs.com/yeer/archive/2010/08/17/1801679.html
不写last和break - 那么流程就是依次执行这些rewrite
- rewrite break - url重写后,直接使用当前资源,不再执行location里余下的语句,完成本次请求,地址栏url不变
- rewrite last - url重写后,马上发起一个新的请求,再次进入server块,重试location匹配,超过10次匹配不到报500错误,地址栏url不变
- rewrite redirect – 返回302临时重定向,地址栏显示重定向后的url,爬虫不会更新url(因为是临时)
- rewrite permanent – 返回301永久重定向, 地址栏显示重定向后的url,爬虫更新url
http://blog.youkuaiyun.com/zhanlanmg/article/details/49684803
phpize安装
//下载libevent扩展文件压缩包(在当前系统哪个目录下载随意)
~# wget http://pecl.php.net/get/libevent-0.1.0.tgz
//解压文件
~# tar -zxvf libevent-0.1.0.tgz
//进入源码目录
~# cd libevent-0.1.0/
//运行phpize命令,写全phpize的路径
~# /usr/local/php/bin/phpize
//运行configure命令,配置时 要将php-config的路径附上
~# ./configure --with-php-config=/usr/local/php/bin/php-config
//运行make命令
~# make
//测试编译安装
~# make test
//正式编译安装
~# sudo make install
//修改php.ini,结尾加入:extension=libevent.so
//重启对应的php-fpm