<?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>写意生活 &#187; PHP</title>
	<atom:link href="http://x1989.com/a/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://x1989.com</link>
	<description>小谢的Blog — 认真生活 快乐工作 专注Web前后端开发&#124;移动平台</description>
	<lastBuildDate>Sat, 08 Oct 2011 10:21:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP模拟BigPipe</title>
		<link>http://x1989.com/a/469.html</link>
		<comments>http://x1989.com/a/469.html#comments</comments>
		<pubDate>Sat, 08 Oct 2011 08:20:58 +0000</pubDate>
		<dc:creator>xhowhy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web开发]]></category>
		<category><![CDATA[BigPipe]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[前端]]></category>

		<guid isPermaLink="false">http://x1989.com/?p=469</guid>
		<description><![CDATA[前不久新浪微博改版，前端引入了BigPipe（最早是Facebook提出的），页面载入速度嗖嗖嗖地上去了。。那末为神马BigPipe能这么快呢？

与AJAX相似，BigPipe使页面可以按区块渲染。但与AJAX不同的是，BigPipe不需要在页面载入后再通过XMLHttpRequest向服务器发起异步请求，而是（通过使用缓冲区）在页面载入过程中先输出页面布局，并在HTML中预留各个页面区块（Facebook称为Pagelet），在页面底部才输出Javascript代码，DOM操作，从而对区块进行内容填充，也就是把内容赋给innerHTML。

<span class="readmore"><a href="http://x1989.com/a/469.html" title="PHP模拟BigPipe">阅读全文——共1439字</a></span>]]></description>
			<content:encoded><![CDATA[<p>前不久新浪微博改版，前端引入了BigPipe（最早是Facebook提出的），页面载入速度嗖嗖嗖地上去了。。那末为神马BigPipe能这么快呢？<br />
与AJAX相似，BigPipe使页面可以按区块渲染。但与AJAX不同的是，BigPipe不需要在页面载入后再通过XMLHttpRequest向服务器发起异步请求，而是（通过使用缓冲区）在页面载入过程中先输出页面布局，并在HTML中预留各个页面区块（Facebook称为Pagelet），在页面底部才输出Javascript代码，DOM操作，从而对区块进行内容填充，也就是把内容赋给innerHTML。<br />
这么做的好处是，在页面加载的过程中，把一些响应时间相对较长的输出放到了页面底部，而页面整体轮廓先显示出来，减少用户的等待时间；此外，与Ajax相比，BigPipe不需要进行多次请求就能完全显示内容，降低了服务器的负担。<br />
下面用PHP模拟一下BigPipe，代码里用sleep(1)模拟一些运算的时间损耗（要先关闭Apache的GZip）：</p>
<pre>
&lt;!doctype&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;meta charset=&quot;utf-8&quot; /&gt;
	&lt;title&gt;PHP模拟BigPipe&lt;/title&gt;
&lt;/head&gt;
&lt;style&gt;
.section{height:200px;}
#con1{background:#ef8090;}
#con2{background:#fef000;}
#con3{background:#19c000;}
&lt;/style&gt;
&lt;body&gt;
	&lt;div class=&quot;wrapper&quot;&gt;
		&lt;div class=&quot;section&quot; id=&quot;con1&quot;&gt;页头内容，正在加载……&lt;/div&gt;
		&lt;div class=&quot;section&quot; id=&quot;con2&quot;&gt;正文内容，正在加载……&lt;/div&gt;
		&lt;div class=&quot;section&quot; id=&quot;con3&quot;&gt;页尾内容，正在加载……&lt;/div&gt;
	&lt;/div&gt;
	&lt;?php
	/*
	 * 输出缓存区
	 */
	function flush_now(){
		ob_flush();
		flush();
	}
	flush_now();
	?&gt;

	&lt;?php sleep(1);?&gt;
	&lt;script&gt;
		document.getElementById(&quot;con1&quot;).innerHTML = &quot;&lt;?php echo str_repeat(\'内容1\', 200) ?&gt;&quot;;
	&lt;/script&gt;
	&lt;?php flush_now()?&gt;

	&lt;?php sleep(1);?&gt;
	&lt;script&gt;
		document.getElementById(&quot;con2&quot;).innerHTML = &quot;&lt;?php echo str_repeat(\'内容2\', 200) ?&gt;&quot;;
	&lt;/script&gt;
	&lt;?php flush_now()?&gt;

	&lt;?php sleep(1);?&gt;
	&lt;script&gt;
		document.getElementById(&quot;con3&quot;).innerHTML = &quot;&lt;?php echo str_repeat(\'内容3\', 200) ?&gt;&quot;;
	&lt;/script&gt;
	&lt;?php flush_now()?&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>这样，打开页面后，页头、正文和页尾的内容一开始显示的是“正在加载……”，但随后内容会逐一显示出来，肿么样，很神奇吧。<br />
<strong>但话说回来，这只是模拟的BigPipe，因为每个区块的内容输出之间是阻塞的，需要等待前一个区块处理完了，才能接着处理后一个。而要真正实现BigPipe就得使用多线程，可以通过CURL的异步模式或者pctnl。</strong> </p>
]]></content:encoded>
			<wfw:commentRss>http://x1989.com/a/469.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Fatal Error重定向跳转</title>
		<link>http://x1989.com/a/362.html</link>
		<comments>http://x1989.com/a/362.html#comments</comments>
		<pubDate>Sat, 26 Mar 2011 06:57:51 +0000</pubDate>
		<dc:creator>xhowhy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web开发]]></category>
		<category><![CDATA[fatal error]]></category>
		<category><![CDATA[handler]]></category>
		<category><![CDATA[重定向]]></category>

		<guid isPermaLink="false">http://x1989.com/?p=362</guid>
		<description><![CDATA[在前端生产环境下，我们需要error_reporting(0)来禁止对用户输出任何错误信息；与此同时，如果能在不可预见地发生Fatal errors和Parse errors的时候跳转到其他页面，而不出现空白，那就能在一定程度上保证用户体验。

我们发现，PHP的error_handlers不能用来处理Fatal errors和Parse errors，于是就有了下面这个方法。

在php.ini文件中可以找到：

<span class="readmore"><a href="http://x1989.com/a/362.html" title="PHP Fatal Error重定向跳转">阅读全文——共525字</a></span>]]></description>
			<content:encoded><![CDATA[<p>在前端生产环境下，我们需要error_reporting(0)来禁止对用户输出任何错误信息；与此同时，如果能在不可预见地发生Fatal errors和Parse errors的时候跳转到其他页面，而不出现空白，那就能在一定程度上保证用户体验。<br />
我们发现，PHP的error_handlers不能用来处理Fatal errors和Parse errors，于是就有了下面这个方法。<br />
在php.ini文件中可以找到：</p>
<pre>
; String to output before an error message.
;error_prepend_string = "html code"
; String to output after an error message.
;error_append_string = "html code"
</pre>
<p>那么我们可以把error_prepend_string或者error_append_string前面的分号去掉，把它的值设置为”&lt;script&gt;window.location.href=&#8217;another_page.php&#8217;;&lt;/script&gt;”，在出错的时候使用javascript的redirect到另一个页面。<br />
但是这种做法似乎不太优雅…正在寻找通过服务器302临时重定向的方法。</p>
]]></content:encoded>
			<wfw:commentRss>http://x1989.com/a/362.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP SPL File Browser</title>
		<link>http://x1989.com/a/359.html</link>
		<comments>http://x1989.com/a/359.html#comments</comments>
		<pubDate>Thu, 24 Mar 2011 12:44:11 +0000</pubDate>
		<dc:creator>xhowhy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web开发]]></category>
		<category><![CDATA[创新工厂]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[Directory]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[SPL]]></category>

		<guid isPermaLink="false">http://x1989.com/?p=359</guid>
		<description><![CDATA[俗话说不想偷懒的程序员不是好程序员。

所以为了向“好程序员”靠拢，我们要自觉地在工作中偷懒…当然不是要你偷工减料，而是要用程序员应该有的方式来“偷懒”，提高工作效率。

我所在的公司使用的PHP demo环境，出于安全方面的考虑，设置了禁止访问网站目录（列出目录文件列表），造成了我没有办法通过浏览器直接访问目录，查看到目录下的文件列表。上传了个php探针到demo服务器上，发现PHP的系列文件操作函数都被禁用了。这样我也没有办法写一段php脚本通过opendir、chdir、scandir等函数来遍历目录下的文件，输出文件列表到浏览器。

<span class="readmore"><a href="http://x1989.com/a/359.html" title="PHP SPL File Browser">阅读全文——共469字</a></span>]]></description>
			<content:encoded><![CDATA[<p>俗话说不想偷懒的程序员不是好程序员。<br />
所以为了向“好程序员”靠拢，我们要自觉地在工作中偷懒…当然不是要你偷工减料，而是要用程序员应该有的方式来“偷懒”，提高工作效率。<br />
我所在的公司使用的PHP demo环境，出于安全方面的考虑，设置了禁止访问网站目录（列出目录文件列表），造成了我没有办法通过浏览器直接访问目录，查看到目录下的文件列表。上传了个php探针到demo服务器上，发现PHP的系列文件操作函数都被禁用了。这样我也没有办法写一段php脚本通过opendir、chdir、scandir等函数来遍历目录下的文件，输出文件列表到浏览器。<br />
好在经过测试，发现并没有禁用PHP的SPL(SPL是Standard PHP Library的缩写)。这样我们就可以通过SPL中的DirectoryIterator来遍历目录了。<br />
于是就有了下面这个小工具，我想可以把它叫做PHP SPL File Browser或者PHP SPL Directory Browser。它强大得放在任意子目录下都可以浏览整站目录。代码写得很乱，就不献丑了，有需要的童鞋可以发Email给我。<br />
<a href="http://x1989.com/wp-content/uploads/2011/03/phpspldirectorybrowser.png"><img src="http://x1989.com/wp-content/uploads/2011/03/phpspldirectorybrowser-300x226.png" alt="" title="phpspldirectorybrowser" width="300" height="226" class="alignnone size-medium wp-image-382" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://x1989.com/a/359.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

