﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gavin&#039;s Blog &#187; 默认分类</title>
	<atom:link href="http://laigw.name/cat/default/feed" rel="self" type="application/rss+xml" />
	<link>http://laigw.name</link>
	<description>Keep it simple, stupid. Simplicity is beauty.</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:14:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>使用PHP进行异步HTTP请求</title>
		<link>http://laigw.name/post/440.html</link>
		<comments>http://laigw.name/post/440.html#comments</comments>
		<pubDate>Wed, 20 Jul 2011 07:57:57 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[默认分类]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[异步请求]]></category>

		<guid isPermaLink="false">http://laigw.name/?p=440</guid>
		<description><![CDATA[使用PHP进行异步HTTP请求

使用JavaScript/Ajax可轻松实现异步HTTP请求，本文介绍使用PHP进行异步HTTP请求。所谓异步HTTP请求是指：HTTP协议基于TCP且是基于状态的，client和server建立连接后发送请求需要等到server处理结束并返回后才可以断开连接。某些情况下，client端只需要发出自己的请求即可，不需要知道server端的响应，这个时候即需要实现client端发出异步HTTP请求。另外，在长耗时应用中(请求的server端任务比较耗时，超过HTTP timeout时间甚至更长)，也可以考虑使用异步HTTP请求出发该任务。关于长耗时应用也可以参考该文。


方法1：使用curl的CURLOPT_TIMEOUT或CURLOPT_TIMEOUT_MS
设置CURLOPT_TIMEOUT为最小值1，client端在等待1秒之后即返回。

&#160;查看代码 PHP1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$url = &#34;http://www.yoursite.com/background-script.php&#34;;
$ref_url = &#34;http://www.yoursite.com&#34;;
$data = array&#40;
	&#34;key1&#34; =&#62; &#34;value1&#34;,
	&#34;key2&#34; =&#62; &#34;value2&#34;,
&#41;;
&#160;
$ch = curl_init&#40;&#41;;
curl_setopt&#40;$ch, CURLOPT_URL, $url&#41;;
curl_setopt&#40;$ch, CURLOPT_USERAGENT, $agent&#41;;
curl_setopt&#40;$ch, CURLOPT_REFERER, $ref_url&#41;;
&#160;
curl_setopt&#40;$ch, CURLOPT_SSL_VERIFYHOST, 0&#41;;
curl_setopt&#40;$ch, CURLOPT_SSL_VERIFYPEER, 0&#41;;
&#160;
curl_setopt&#40;$ch, CURLOPT_POST, TRUE&#41;;
curl_setopt&#40;$ch, CURLOPT_POSTFIELDS, $data&#41;;        
&#160;
curl_setopt&#40;$ch, CURLOPT_TIMEOUT, 1&#41;;
&#160;
curl_exec&#40;$ch&#41;;
curl_close&#40;$ch&#41;;

如果是cURL 7.16.2 or higher and PHP 5.2.3 or above，可以设置Timeout时间为1 ms，实现立即返回，修改如上的curl_setopt($ch, CURLOPT_TIMEOUT, 1);为curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1);。

方法2：使用socket修改HTTP header
使用socket连接到server上，发送raw HTTP header(注意设置Connection: [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/440.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>jQuery性能优化实践</title>
		<link>http://laigw.name/post/410.html</link>
		<comments>http://laigw.name/post/410.html#comments</comments>
		<pubDate>Sun, 31 Oct 2010 06:50:32 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[Web前端技术]]></category>
		<category><![CDATA[默认分类]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[优化]]></category>
		<category><![CDATA[实践]]></category>
		<category><![CDATA[性能]]></category>

		<guid isPermaLink="false">http://laigw.name/?p=410</guid>
		<description><![CDATA[代码优化分多个方面，而性能是主要的优化目标。本文将从对象缓存、DOM操作等14个方面讲解如何优化jQuery代码的执行效率，从而总体提升代码性能。]]></description>
		<wfw:commentRss>http://laigw.name/post/410.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>大小不固定的图片和多行文字的垂直水平居中</title>
		<link>http://laigw.name/post/405.html</link>
		<comments>http://laigw.name/post/405.html#comments</comments>
		<pubDate>Wed, 13 Oct 2010 09:03:43 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[Web前端技术]]></category>
		<category><![CDATA[默认分类]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[图片居中]]></category>
		<category><![CDATA[垂直居中]]></category>
		<category><![CDATA[多行]]></category>
		<category><![CDATA[文字居中]]></category>

		<guid isPermaLink="false">http://laigw.name/?p=405</guid>
		<description><![CDATA[大小不固定的图片和多行文字的垂直水平居中

一、大小不固定，多行文字的垂直居中
① 单行文字
可能很多人都知道如何让单行文字垂直居中显示，就是使用line-height，将line-height值与外部标签盒子的高度值设置成一致就可以了。例如：
单行文字居中显示测试，css样式为：height:3em; line-height:3em;……
② 多行文字
但是对于外框高度固定，文字大小个数不固定的多行文字呢？
文字可能一行显示，也有可能多行显示；文字可能是小号字体，也有可能是大号的。这时候如何让其垂直居中显示呢？看下面！
这里的文字用来做多行文字垂直居中对齐的测试。
这是第二行文字，您还可以再添加一行文字做测试！
这是隐藏的第三行文字，注意到文字的变化没，依旧垂直居中。

详见：http://xurl.cn/bhfqf

]]></description>
		<wfw:commentRss>http://laigw.name/post/405.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linux系统信息查看命令大全</title>
		<link>http://laigw.name/post/400.html</link>
		<comments>http://laigw.name/post/400.html#comments</comments>
		<pubDate>Tue, 24 Aug 2010 07:48:00 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[默认分类]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Slackware]]></category>

		<guid isPermaLink="false">http://laigw.name/?p=400</guid>
		<description><![CDATA[最近看了一些Linux命令行的文章，在系统信息查看方面学到不少命令。想起以前写过的一篇其实Linux这样用更简单，发现这些系统信息查看命令也可以总结出一篇小小的东西来了。
另外这里还有非常多的命令，可以作为参考。
系统

&#160;查看代码 PERL1
2
3
4
5
6
7
8
# uname -a               # 查看内核/操作系统/CPU信息
# head -n 1 /etc/issue   # 查看操作系统版本
# cat /proc/cpuinfo      # 查看CPU信息
# hostname               # 查看计算机名
# lspci [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/400.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx Rewrite 参数和例子</title>
		<link>http://laigw.name/post/394.html</link>
		<comments>http://laigw.name/post/394.html#comments</comments>
		<pubDate>Tue, 24 Aug 2010 03:57:22 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[默认分类]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://laigw.name/?p=394</guid>
		<description><![CDATA[
推荐参考地址：
Mailing list ARChives 官方讨论区
http://marc.info/?l=nginx
Nginx 常见应用技术指南[Nginx Tips]
http://bbs.linuxtone.org/thread-1685-1-1.html
本日志内容来自互联网和平日使用经验，整理一下方便日后参考。
正则表达式匹配，其中：
* ~ 为区分大小写匹配

* ~* 为不区分大小写匹配
* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配
文件及目录匹配，其中：
* -f和!-f用来判断是否存在文件
* -d和!-d用来判断是否存在目录
* -e和!-e用来判断是否存在文件或目录
* -x和!-x用来判断文件是否可执行

flag标记有：
* last 相当于Apache里的[L]标记，表示完成rewrite
* break 终止匹配, 不再匹配后面的规则
* redirect 返回302临时重定向 地址栏会显示跳转后的地址
* permanent 返回301永久重定向 地址栏会显示跳转后的地址

一些可用的全局变量有，可以用做条件判断(待补全)

$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri


结合QeePHP的例子
if (!-d $request_filename) {
rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&#38;amp;controller=$1&#38;amp;action=$2&#38;amp;$3 last;
rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&#38;amp;controller=$1 last;
break;

多目录转成参数
abc.domian.com/sort/2 =&#62; abc.domian.com/index.php?act=sort&#38;name=abc&#38;id=2
if ($host ~* (.*)\.domain\.com) {
set $sub_name $1;   
rewrite ^/sort\/(\d+)\/?$ /index.php?act=sort&#38;cid=$sub_name&#38;id=$1 last;
}

目录对换
/123456/xxxx -&#62; /xxxx?id=123456
rewrite ^/(\d+)/(.+)/ /$2?id=$1 last;
例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下：
if ($http_user_agent ~ MSIE) [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/394.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://laigw.name/post/1.html</link>
		<comments>http://laigw.name/post/1.html#comments</comments>
		<pubDate>Thu, 13 Nov 2008 19:51:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[默认分类]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=1</guid>
		<description><![CDATA[    Welcome to WordPress.
    This is your first post. Edit or delete it, then start blogging!
]]></description>
		<wfw:commentRss>http://laigw.name/post/1.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

