<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[静怡家园]]></title> 
<link>http://www.zhanghaijun.com/index.php</link> 
<description><![CDATA[书山有路勤为径，学海无涯苦作舟！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[静怡家园]]></copyright>
<item>
<link>http://www.zhanghaijun.com/post//</link>
<title><![CDATA[加速PHP的代码]]></title> 
<author>碟舞飞扬 &lt;webmaster@zhanghaijun.com&gt;</author>
<category><![CDATA[Web开发]]></category>
<pubDate>Sat, 03 Feb 2007 19:05:31 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//</guid> 
<description>
<![CDATA[ 
	eAccelerator 真是一个好东西（它的前身是truck-mmcache）。 <br/><br/>简单来讲它是一套配合PHP（支持PHP5）运作的缓存系统，通过共享内存或磁盘文件方式交换数据。 <br/><br/>它被广为使用的是PHP源码“编码”（不太贴切的称为“加密”）和缓存PHP执行的中间码以加速。关于 eA 的安装使用的文章已经很多而且也很详细了，这次我想推荐的是用它辅助程序设计缓存，它提供了一组API如下： <br/><br/>是一个非常便捷而又稳定的本机缓存实现方式，目前这部分设计似乎只支持于共享内存，所以只能用于 Unix -Like OS 了，windows的就没这个福气了。 <br/><br/>1. eaccelerator_put($key, $value, $ttl=0) <br/>&nbsp;&nbsp;将 $value 以 $key 为键名存进缓存(php4下支持对像类型，看源码好像zend2里不支持了)，$ttl 是这个缓存的生命周期，单位是秒，省略该参数或指定为 0 表示不限时，直到服务器重启清空为止。 <br/><br/>2. eaccelerator_get($key) <br/>&nbsp;&nbsp;根据 $key 从缓存中返回相应的 eaccelerator_put() 存进去的数据，如果这项缓存已经过期或不存在那么返回值是 NULL <br/><br/>3. eaccelerator_rm($key) <br/>&nbsp;&nbsp;根据 $key 移除缓存 <br/><br/>4. eaccelerator_gc() <br/>&nbsp;&nbsp;移除清理所有已过期的 key&nbsp;&nbsp;<br/><br/>5. eaccelerator_lock($key) <br/>&nbsp;&nbsp;为 $key 加上锁定操作，以保证多进程多线程操作时数据的同步。需要调用 eaccelerator_unlock($key) 来释放这个锁或等待程序请求结束时自动释放这个锁。 <br/>&nbsp;&nbsp;例如: <br/>&nbsp;&nbsp;&lt;?php <br/>&nbsp;&nbsp;&nbsp;&nbsp;eaccelerator_lock(&quot;count&quot;); <br/>&nbsp;&nbsp;&nbsp;&nbsp;eaccelerator_put(&quot;count&quot;,eaccelerator_get(&quot;count&quot;)+1)); <br/>&nbsp;&nbsp;?&gt; <br/><br/>6. eaccelerator_unlock($key) <br/>&nbsp;&nbsp;根据 $key 释放锁 <br/><br/>7. eaccelerator_cache_output($key, $eval_code, $ttl=0) <br/>&nbsp;&nbsp;将 $eval_code 代码的输出缓存 $ttl 秒，（$ttl参数同 eacclerator_put） <br/>&nbsp;&nbsp; For Example: <br/>&nbsp;&nbsp;&lt;?php eaccelerator_cache_output(&#039;test&#039;, &#039;echo time(); phpinfo();&#039;, 30); ?&gt; <br/><br/>8. eaccelerator_cache_result($key, $eval_code, $ttl=0) <br/>&nbsp;&nbsp;将 $eval_code 代码的执行结果缓存 $ttl 秒，（$ttl参数同 eacclerator_put），类似 cache_output <br/>&nbsp;&nbsp; For Example: <br/>&nbsp;&nbsp;&lt;?php eaccelerator_cache_result(&#039;test&#039;, &#039; time() . &quot;Hello&quot;;&#039;, 30); ?&gt; <br/><br/>9. eaccelerator_cache_page($key, $ttl=0) <br/>&nbsp;&nbsp;将当前整页缓存 $ttl 秒。 <br/>&nbsp;&nbsp;For Example: <br/>&nbsp;&nbsp;&lt;?php <br/>&nbsp;&nbsp;&nbsp;&nbsp;eaccelerator_cache_page($_SERVER[&#039;PHP_SELF&#039;].&#039;?GET=&#039;.serialize($_GET),30); <br/>&nbsp;&nbsp;&nbsp;&nbsp;echo time(); <br/>&nbsp;&nbsp;&nbsp;&nbsp;phpinfo(); <br/>&nbsp;&nbsp;?&gt; <br/><br/>10. eaccelerator_rm_page($key) <br/>&nbsp;&nbsp;删除由&nbsp;&nbsp;eaccelerator_cache_page() 执行的缓存，参数也是 $key <br/><br/>______________________________________________ <br/>(作个简单例子看看它的威力，注意在 cli 模式下可能无效！） <br/><br/><br/>&lt;?php<br/>class test_cache { <br/>&nbsp;&nbsp;var $pro = &#039;hello&#039;;<br/><br/>&nbsp;&nbsp;function test_cache() { <br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Object Created!&lt;br&gt; &quot;; <br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;function func() { <br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;, the world!&#039;;<br/>&nbsp;&nbsp;} <br/>&nbsp;&nbsp;function now($t) { <br/>&nbsp;&nbsp;&nbsp;&nbsp;echo date(&#039;Y-m-d H:i:s&#039;, $t); <br/>&nbsp;&nbsp;}<br/>}<br/><br/>$tt = eaccelerator_get(&quot;test_tt&quot;); <br/>if (!$tt)<br/>{<br/>&nbsp;&nbsp;$tt = new test_cache; <br/>&nbsp;&nbsp;eaccelerator_put(&quot;test_tt&quot;, $tt); <br/>&nbsp;&nbsp;echo &quot;no cached!&lt;br&gt; &quot;;<br/>}<br/>else { <br/>&nbsp;&nbsp;echo &quot;cached&lt;br&gt; &quot;;<br/>}<br/><br/>echo $tt-&gt;pro; <br/>$tt-&gt;func(); <br/>$tt-&gt;now(time() + 86400);<br/>?&gt;
]]>
</description>
</item><item>
<link>http://www.zhanghaijun.com/post//#blogcomment</link>
<title><![CDATA[[评论] 加速PHP的代码]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>