<?xml version="1.0" encoding="utf-8" ?><rss version="2.0">
<channel>
<title><![CDATA[小康的blog]]></title>
<link>http://www.kanglog.com</link>
<description><![CDATA[发布基于ajax的blog程序]]></description>
<language></language>
<copyright><![CDATA[Copyright 2008, 小康的blog]]></copyright>
<webMaster><![CDATA[ (小康)]]></webMaster>
<generator></generator>
<pubDate>2008</pubDate>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&96]]></link>
	<title><![CDATA[鲁迅《聪明人和傻子和奴才》]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[他人语录]]></category>
	<pubDate>2008-07-05 20:09:12</pubDate>
	<description><![CDATA[奴才总不过是寻人诉苦。只要这样，也只能这样。有一曰，他遇到一个聪明人。 <br />　　先生！他悲哀地说，眼泪联成一线，就从眼角上直流下来。你知道的。我所过的简直不是人的生活。吃的是一天未必有一餐，这一餐又不过是高粱皮，连猪狗都不要吃的，尚且只有一小碗 <br />　　这实在令人同情。聪明人也惨然说。 <br />　　可不是么！他高兴了。可是做工是昼夜无休息：清早担水晚烧饭，上午跑街夜磨面，晴洗衣裳雨张伞，冬烧汽炉夏打扇。半夜要煨银耳，侍候主人耍钱；头钱从来没分，有时还挨皮鞭。 <br />　　唉唉聪明人叹息着，眼圈有些发红，似乎要下泪。 <br />　　先生！我这样是敷衍不下去的。我总得另外想法子。可是什么法子呢？ <br />　　我想，你总会好起来 <br />　　是么？但愿如此。可是我对先生诉了冤苦，又得你的同情和慰安，已经舒坦得不少了。可见天理没有灭绝 <br />　　但是，不几曰，他又不平起来了，仍然寻人去诉苦。 <br />　　先生！他流着眼泪说，你知道的。我住的简直比猪窝还不如。主人并不将我当人；他对他的叭儿狗还要好到几万倍 <br />　　混帐！那人大叫起来，使他吃惊了。那人是一个傻子。 <br />　　先生，我住的只是一间破小屋，又湿，又阴，满是臭虫，睡下去就咬得真可以。秽气冲着鼻子，四面又没有一个窗子 <br />　　你不会要你的主人开一个窗的么？ <br />　　这怎么行？ <br />　　那么，你带我去看去！ <br />　　傻子跟奴才到他屋外，动手就砸那泥墙。 <br />　　先生！你干什么？他大惊地说。 <br />　　我给你打开一个窗洞来。 <br />　　这不行！主人要骂的！ <br />　　管他呢！他仍然砸。 <br />　　人来呀！强盗在毁咱们的屋子了！快来呀！迟一点可要打出窟窿来了！他哭嚷着，在地上团团地打滚。 <br />　　一群奴才都出来，将傻子赶走。 <br />　　听到了喊声，慢慢地最后出来的是主人。 <br />　　有强盗要来毁咱们的屋子，我首先叫喊起来，大家一同把他赶走了。他恭敬而得胜地说。 <br />　　你不错。主人这样夸奖他。 <br />　　这一天就来了许多慰问的人，聪明人也在内。 <br />　　先生。这回因为我有功，主人夸奖了我了。你先前说我总会好起来，实在是有先见之明。他大有希望似的高兴地说。 <br />　　可不是么聪明人也代为高兴似的回答他。 <br /><br />　　　　　　　　　　　　　　　　　　　　　 一九二五年十二月二十六曰。]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&95]]></link>
	<title><![CDATA[程序更新记录]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[程序相关]]></category>
	<pubDate>2008-06-30 01:16:18</pubDate>
	<description><![CDATA[新增本blog程序与QQ空间同步功能。<br />]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&93]]></link>
	<title><![CDATA[来自www.kanglog.com的日志]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[默认]]></category>
	<pubDate>2008-06-30 01:07:19</pubDate>
	<description><![CDATA[这是一封来自<a href="../">www.kanglog.com</a>的日志，测试下。]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&92]]></link>
	<title><![CDATA[让IE7与IE6共存的方法]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[think_php]]></category>
	<pubDate>2008-01-29 17:23:15</pubDate>
	<description><![CDATA[<p>如果你是进行网页制作，网站开发的话可能就需要用到多浏览器随时浏览页面制作在各个浏览器里面的效果和兼容性了，无奈安装的是IE6的话，就没办法到IE7里面看，升级成为IE7的话IE6就又消失了，难道还得跑到装了IE6的电脑上看？下面我来教大家个方法。具体步骤如下：<br />下载IE7 Standalone 这个工具，本地下载地址：<br /><a href="DNGZup/UpFiles/ie7green.rar">点击这里下载！</a></p><p>解压缩 IE7green.rar 到任一空目录中。</p><p>根据你的系统下载合适你的IE7安装文件，这个到处都是，搜索一下就一大把，我这里就不提供了。</p><p>将 IE7 的安装文件（例如：IE7-Windows2003-x86-zh.exe）改名为IE7SetupFile.exe保存到刚刚的目录中，就是要和 IE7green.rar 解压缩出来的文件保存在同一个目录中。如下图：<br /><img src="http://www.dngz.net/blog/DNGZup/UpFiles/ie7green01.gif" border="0" width="392" height="351" /></p><p>运行目录中的 IE7 Standalone Setup.bat 批处理程序。这个程序会解压缩 IE7 的安装文件到 Installation 子目录中。</p><p>运行目录中的 ie7.bat 就可以启动 ie7 了。注意启动的时候会出现一个 dos 窗口，不能关闭这个窗口，15 秒后这个窗口会自动关闭。<br /><img src="http://www.dngz.net/blog/DNGZup/UpFiles/ie7green02.gif" border="0" width="428" height="338" /></p><p>IE7,IE6,<a href="http://www.dngz.net/firefox/">FireFox</a>,同时运行的效果图就如下了，不错吧。<br /><img src="http://www.dngz.net/blog/DNGZup/UpFiles/ie7green03.gif" border="0" width="548" height="484" /><br />如果你不是为了进行web标准页面兼容性开发，完全没有必要搞这个好玩。所以下面的话是对web标准页面开发者说的]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&90]]></link>
	<title><![CDATA[2008-01-28]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[think_php]]></category>
	<pubDate>2008-01-28 00:08:47</pubDate>
	<description><![CDATA[厌恶了fckeditor，换了html编辑器，用tinymce.测试下。还是不理想，很想自己写个html编辑器。<br /><br />]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&89]]></link>
	<title><![CDATA[写在年前]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[think_php]]></category>
	<pubDate>2008-01-26 20:45:05</pubDate>
	<description><![CDATA[<p>06年下半年至此刻，不知不觉一年半。</p>
<p>累过也闲过，空虚也充实过，正如qq签名所说：我很累，但是很充实。我想我的生命在进入大学之前，从来没有看到过光，一直很暗淡，更不用说充实。偶尔觉得大学之前无所作为，浪费了生命，那是人生必经的阶段吧？由幼稚走向成熟的阶段。</p>
<p>从出生到现在，我为人正直，是个好人，这点已经让我很满足了。</p>
<p>进入大学，感觉到天空很自由，我可以尽情努力展翅飞翔，积蓄力量。正如我大一上学期的一篇英文作文所说，大学的压力相比高中有形的压力，是无形的。</p>
<p>大一上学期在很放松的状态下，自学了C和java，开始了我的编程之路。寒假去了广东我表姐那里玩，偶尔帮他们修电脑，自己写或者帮别人写些简单的java程序。</p>
<p>大一下学期累了几个月，攻jsp和ajax。写了这个blog程序，并不断总结和思考。顺便接触了php，sql，数据库等等一些附属品。暑假贡献给了数据结构与算法，虽然那段时间很压抑。</p>
<p>大二上学期，搬出学校体验了校外租住生活，和鸽子合作写了个订餐网站，然后开发webgame，进一步巩固了java基础，对编程有了更多领悟和思考。勇敢的追求了我喜欢的女生，让我感到很幸福。</p>
<p>在此期间，没参加任何社团和商业活动，与商仕保持了足够的距离，但是又没有放过了解的机会，并非不感兴趣，没有自信，相反自信十足，只是不想过早的脱离学习生活，毕竟大学的时光对我来说是相当宝贵和难得的机会，我需要借此翻身。</p>
<p>有时候会想，我是不是太急了，感觉好像自己被自己拔苗助长，感觉很痛苦，很累，身体和心脏有点失衡，也许自己的压力太大了。但是确实没办法，我已经落后很多人很多步了。</p>
<p>虽然相比其他人感觉到这一年半还是在学，还是在做事，但实际上不是把时间利用到我理想的状态，所谓理想状态并非废寝忘食，而是应当进一步生活效率提高效率和质量。</p>
<p>自己给自己这一年半打分，只有70分。从上面回顾来看，总共浪费了至少半年以上的时间。惭愧。经过这一年半，只能自我承认，我是个很好的菜鸟。所谓菜鸟，还是菜。还有很多计算机底层没有深入接触，只是会了很多人都会，很多人都容易学的东西，也许比别人学得快点而已。现在连技术员都算不上。</p>
<p>这次回家，和爸妈商量了，打算尽全力努力出国。为了达到这个目的，我需要更加注重我的生活和学习，学好外语、数学、计算机等，争取尽快自己挣到足够的钱，然后出国，出国的事我不想靠父母了。</p>
<p>我得加油，所以下学期还是按照原计划，多看书，沉淀一下，也是一种放松。</p>
<p>时常思考人生的未来，挺恐怖，生命确实短暂，至少我没有资本去挥霍。马上就20，然后30，然后40，然后50，然后度晚年，然后离开人世。想到就恐怖。人生有几个10年？我想我早已经做好充足的心理准备，没有什么人什么物能把我打垮。</p>
<p>ok，说了这么多话，进入大学，我一直很自信，对自己的现状比较满意，只是我想，我还可以并且应该做到更好。在此自勉，加油。</p>]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&88]]></link>
	<title><![CDATA[皮肤兼容pjblog、lbs、bo-blog]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[think_php]]></category>
	<pubDate>2008-01-26 16:30:07</pubDate>
	<description><![CDATA[<p>小小修改了下，让我的blog程序的皮肤适应pjblog、lbs、bo-blog。哈哈。</p><p><img src="attachment/pic_2008_1_26.jpg" border="0" width="422" height="300" /></p>]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&87]]></link>
	<title><![CDATA[2008-01-26]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[think_php]]></category>
	<pubDate>2008-01-26 13:22:03</pubDate>
	<description><![CDATA[虽说接触ajax很久，但为了方便一直都用的json。为了研究QQ空间的数据源，顺便获取，不得已又研究用javascript解析xml，解析的麻烦之处在于要兼顾IE和firefox，痛苦。<br />
<br />
以前qq空间都不支持firefox的，现在居然部分支持了，有进步，故障。<br />
<br />
研究成果就是把QQ空间的签名比较顺利的截取过来，然后又把javascript面向对象复习了一下，然后又把blog程序客服端和服务器端优化了很多。粗略看了下prototype.js，作者的确不赖，学习了。]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&86]]></link>
	<title><![CDATA[在IE下的JS编程需注意的内存释放问题（转）]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[think_php]]></category>
	<pubDate>2008-01-22 17:32:44</pubDate>
	<description><![CDATA[在IE下的JS编程中，以下的编程方式都会造成即使关闭IE也无法释放内存的问题，下面分类给出：<br />
<br />
<font color="red">1、给DOM对象添加的属性是一个对象的引用。范例：</font><br />
var MyObject =  {};<br />
document.getElementById(‘myDiv‘).myProp = MyObject;<br />
<font color="green">解决方法</font>：<br />
在window.onunload事件中写上:  document.getElementById(‘myDiv‘).myProp = null;<br />
<br />
<br />
<font color="red">2、DOM对象与JS对象相互引用。范例：</font><br />
function Encapsulator(element)  {<br />
&nbsp;&nbsp;this.elementReference = element;<br />
&nbsp;&nbsp;element.myProp =  this;<br />
}<br />
new&nbsp;&nbsp;Encapsulator(document.getElementById(‘myDiv‘));<br />
<font color="green">解决方法</font>：<br />
在onunload事件中写上:  document.getElementById(‘myDiv‘).myProp = null;<br />
<br />
<br />
<font color="red">3、给DOM对象用attachEvent绑定事件。范例：</font><br />
function doClick()  {}<br />
element.attachEvent(&quot;onclick&quot;, doClick);<br />
<font color="green">解决方法</font>：<br />
在onunload事件中写上: element.detachEvent(‘onclick‘,  doClick);<br />
<br />
<br />
<font color="red">4、从外到内执行appendChild。这时即使调用removeChild也无法释放。范例：</font><br />
var parentDiv  =&nbsp;&nbsp;document.createElement(&quot;div&quot;);<br />
var childDiv =  document.createElement(&quot;div&quot;);<br />
document.body.appendChild(parentDiv);<br />
parentDiv.appendChild(childDiv);<br />
<font color="green">解决方法</font>：<br />
从内到外执行appendChild:<br />
var parentDiv  =&nbsp;&nbsp;document.createElement(&quot;div&quot;);<br />
var childDiv =  document.createElement(&quot;div&quot;);<br />
parentDiv.appendChild(childDiv);<br />
document.body.appendChild(parentDiv);<br />
<br />
<br />
<font color="red">5、反复重写同一个属性会造成内存大量占用(但关闭IE后内存会被释放)。范例：</font><br />
for(i = 0; i &lt;  5000; i++) {<br />
&nbsp;&nbsp;hostElement.text =  &quot;asdfasdfasdf&quot;;<br />
}<br />
这种方式相当于定义了5000个属性！<br />
<font color="green">解决方法：</font><br />
其实没什么解决方法:P~~~就是编程的时候尽量避免出现这种情况咯~~]]></description>
</item>
<item>
    <link><![CDATA[http://www.kanglog.comindex.php?#article&85]]></link>
	<title><![CDATA[（译文）优化PHP代码的40条建议]]></title>
	<author><![CDATA[小康]]></author>
	<category><![CDATA[think_php]]></category>
	<pubDate>2008-01-22 16:49:31</pubDate>
	<description><![CDATA[原文地址：<a target="_blank" href="http://reinholdweber.com/?p=3">http://reinholdweber.com/?p=3</a><br />
英文版权归Reinhold Weber所有，中译文作者yangyang（aka davidkoree）。双语版可用于非商业传播，但须注明英文版作者、版权信息，以及中译文作者。翻译水平有限，请广大PHPer指正。<br />
<br />
1.&nbsp; &nbsp; If a method can be static, declare it static. Speed improvement is by a factor of 4. 如果一个方法可静态化，就对它做静态声明。速率可提升至4倍。<br />
<br />
2.&nbsp; &nbsp; <em>echo</em> is faster than <em>print</em>. <em>echo</em> 比 <em>print</em> 快。<br />
<br />
3.&nbsp; &nbsp; Use echo&rsquo;s multiple parameters instead of string concatenation. 使用echo的多重参数（译注：指用逗号而不是句点）代替<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%D7%D6%B7%FB">字符</span>串连接。<br />
<br />
4.&nbsp; &nbsp; Set the maxvalue for your for-loops before and not in the loop. 在执行for循环之前确定最大循环数，不要每循环一次都计算最大值。<br />
<br />
5.&nbsp; &nbsp; Unset your variables to free memory, especially large arrays. 注销那些不用的变量尤其是大数组，以便释放内存。<br />
<br />
6.&nbsp; &nbsp; Avoid magic like __get, __set, __autoload 尽量避免使用__get，__set，__autoload。<br />
<br />
7.&nbsp; &nbsp; require_once() is expensive require_once()代价昂贵。<br />
<br />
8.&nbsp; &nbsp; Use full paths in includes and requires, less time spent on resolving the OS paths. 在包含文件时使用完整路径，解析操作系统路径所需的时间会更少。<br />
<br />
9.&nbsp; &nbsp; If you need to find out the time when the script started executing, $_SERVER[&rsquo;REQUEST_TIME&rsquo;] is preferred to time() 如果你想知道脚本开始执行（译注：即服务器端收到客户端请求）的时刻，使用$_SERVER[&lsquo;REQUEST_TIME&rsquo;]要好于time()。<br />
<br />
10.&nbsp; &nbsp; See if you can use strncasecmp, strpbrk and stripos instead of regex. 检查是否能用strncasecmp，strpbrk，stripos函数代替<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%D5%FD%D4%F2%B1%ED%B4%EF%CA%BD">正则表达式</span>完成相同功能。<br />
<br />
11.&nbsp; &nbsp; str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4. str_replace函数比preg_replace函数快，但strtr函数的效率是str_replace函数的四倍。<br />
<br />
12.&nbsp; &nbsp; If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments. 如果一个字符串替换函数，可接受数组或字符作为参数，并且参数长度不太长，那么可以考虑额外写一段替换代码，使得每次传递参数是一个字符，而不是只写一行代码接受数组作为查询和替换的参数。<br />
<br />
13.&nbsp; &nbsp; It&rsquo;s better to use select statements than multi if, else if, statements. 使用选择分支语句（译注：即switch case）好于使用多个if，else if语句。<br />
<br />
14.&nbsp; &nbsp; Error suppression with @ is very slow. 用@屏蔽错误消息的做法非常低效。<br />
<br />
15.&nbsp; &nbsp; Turn on <span class="t_tag" onclick="tagshow(event)" href="tag.php?name=apache">apache</span>&rsquo;s mod_deflate 打开<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=apache">apache</span>的mod_deflate模块。<br />
<br />
16.&nbsp; &nbsp; Close your database connections when you&rsquo;re done with them. <span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%CA%FD%BE%DD%BF%E2">数据库</span>连接当使用完毕时应关掉。<br />
<br />
17.&nbsp; &nbsp; $row[&rsquo;id&rsquo;] is 7 times faster than $row[id]. $row[&lsquo;id&rsquo;]的效率是$row[id]的7倍。<br />
<br />
18.&nbsp; &nbsp; Error messages are expensive. 错误消息代价昂贵。<br />
<br />
19.&nbsp; &nbsp; Do not use functions inside of for loop, such as for ($x=0; $x &lt; count($array); $x) The count() function gets called each time. 尽量不要在for循环中使用函数，比如for ($x=0; $x &lt; count($array); $x)每循环一次都会调用count()函数。<br />
<br />
20.&nbsp; &nbsp; Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function. 在方法中递增局部变量，速度是最快的。几乎与在函数中调用局部变量的速度相当。<br />
<br />
21.&nbsp; &nbsp; Incrementing a global variable is 2 times slow than a local var. 递增一个全局变量要比递增一个局部变量慢2倍。<br />
<br />
22.&nbsp; &nbsp; Incrementing an object property (eg. $this-&gt;prop++) is 3 times slower than a local variable. 递增一个对象属性（如：$this-&gt;prop++）要比递增一个局部变量慢3倍。<br />
<br />
23.&nbsp; &nbsp; Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one. 递增一个未预定义的局部变量要比递增一个预定义的局部变量慢9至10倍。<br />
<br />
24.&nbsp; &nbsp; Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists. 仅定义一个局部变量而没在函数中调用它，同样会减慢速度（其程度相当于递增一个局部变量）。PHP大概会检查看是否存在全局变量。<br />
<br />
25.&nbsp; &nbsp; Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance. 方法调用看来与类中定义的方法的数量无关，因为我（在测试方法之前和之后都）添加了10个方法，但性能上没有变化。<br />
<br />
26.&nbsp; &nbsp; Methods in derived classes run faster than ones defined in the base class. 派生类中的方法运行起来要快于在基类中定义的同样的方法。<br />
<br />
27.&nbsp; &nbsp; A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations. 调用带有一个参数的空函数，其花费的时间相当于执行7至8次的局部变量递增操作。类似的方法调用所花费的时间接近于15次的局部变量递增操作。<br />
<br />
28.&nbsp; &nbsp; Surrounding your string by &lsquo; instead of &quot; will make things interpret a little faster since php looks for variables inside &quot;&hellip;&quot; but not inside &lsquo;&hellip;&rsquo;. Of course you can only do this when you don&rsquo;t need to have variables in the string. 用单引号代替双引号来包含字符串，这样做会更快一些。因为PHP会在双引号包围的字符串中搜寻变量，单引号则不会。当然，只有当你不需要在字符串中包含变量时才可以这么做。<br />
<br />
29.&nbsp; &nbsp; When echoing strings it&rsquo;s faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments. 输出多个字符串时，用逗号代替句点来分隔字符串，速度更快。注意：只有echo能这么做，它是一种可以把多个字符串当作参数的&ldquo;函数&rdquo;（译注：PHP手册中说echo是语言结构，不是真正的函数，故把函数加上了双引号）。<br />
<br />
30.&nbsp; &nbsp; A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts. Apache解析一个PHP脚本的时间要比解析一个静态HTML页面慢2至10倍。尽量多用静态HTML页面，少用脚本。<br />
<br />
31.&nbsp; &nbsp; Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times. 除非脚本可以<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%BB%BA%B4%E6">缓存</span>，否则每次调用时都会重新编译一次。引入一套PHP<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%BB%BA%B4%E6">缓存</span>机制通常可以提升25%至100%的性能，以免除编译开销。<br />
<br />
32.&nbsp; &nbsp; Cache as much as possible. Use memcached - memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. OP code caches are useful so that your script does not have to be compiled on every request. 尽量做缓存，可使用memcached。memcached是一款高性能的内存对象缓存系统，可用来加速<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%B6%AF%CC%AC">动态</span>Web应用<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%B3%CC%D0%F2">程序</span>，减轻数据库负载。对运算码(OP code)的缓存很有用，使得脚本不必为每个请求做重新编译。<br />
<br />
33.&nbsp; &nbsp; When working with strings and you need to check that the string is either of a certain length you&rsquo;d understandably would want to use the strlen() function. This function is pretty quick since it&rsquo;s operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase &amp; hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick. 当操作字符串并需要检验其长度是否满足某种要求时，你想当然地会使用strlen()函数。此函数执行起来相当快，因为它不做任何计算，只返回在zval结构（C的内置数据结构，用于存储PHP变量）中存储的已知字符串长度。但是，由于strlen()是函数，多多少少会有些慢，因为函数调用会经过诸多步骤，如字母小写化（译注：指函数名小写化，PHP不区分函数名大小写）、哈希查找，会跟随被调用的函数一起执行。在某些情况下，你可以使用isset()技巧加速执行你的代码。<br />
<br />
Ex.（举例如下）<br />
if (strlen($foo) &lt; 5) { echo &quot;Foo is too short&quot;; }<br />
vs.（与下面的技巧做比较）<br />
if (!isset($foo{5})) { echo &quot;Foo is too short&quot;; }<br />
<br />
Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it&rsquo;s execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string&rsquo;s length. 调用isset()恰巧比strlen()快，因为与后者不同的是，isset()作为一种语言结构，意味着它的执行不需要函数查找和字母小写化。也就是说，实际上在检验字符串长度的顶层代码中你没有花太多开销。<br />
<br />
34.&nbsp; &nbsp; When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don&rsquo;t go modifying your C or Java code thinking it&rsquo;ll suddenly become faster, it won&rsquo;t. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend&rsquo;s PHP optimizer. It is still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer. 当执行变量$i的递增或递减时，$i++会比++$i慢一些。这种差异是PHP特有的，并不适用于其他语言，所以请不要修改你的C或Java代码并指望它们能立即变快，没用的。++$i更快是因为它只需要3条指令(opcodes)，$i++则需要4条指令。后置递增实际上会产生一个临时变量，这个临时变量随后被递增。而前置递增直接在原值上递增。这是最优化处理的一种，正如Zend的PHP优化器所作的那样。牢记这个优化处理不失为一个好主意，因为并不是所有的指令优化器都会做同样的优化处理，并且存在大量没有装配指令优化器的互联网服务提供商（ISPs）和服务器。<br />
<br />
35.&nbsp; &nbsp; Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory. 并不是事必面向对象(OOP)，面向对象往往开销很大，每个方法和对象调用都会消耗很多内存。<br />
<br />
36.&nbsp; &nbsp; Do not implement every data structure as a class, arrays are useful, too. 并非要用类实现所有的数据结构，数组也很有用。<br />
<br />
37.&nbsp; &nbsp; Don&rsquo;t split methods too much, think, which code you will really re-use. 不要把方法细分得过多，仔细想想你真正打算重用的是哪些代码？<br />
<br />
38.&nbsp; &nbsp; You can always split the code of a method later, when needed. 当你需要时，你总能把代码分解成方法。<br />
<br />
39.&nbsp; &nbsp; Make use of the countless predefined functions. 尽量采用大量的PHP内置函数。<br />
<br />
40.&nbsp; &nbsp; If you have very time consuming functions in your code, consider writing them as C extensions. 如果在代码中存在大量耗时的函数，你可以考虑用C扩展的方式实现它们。<br />
<br />
41.&nbsp; &nbsp; Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview. 评估检验(profile)你的代码。检验器会告诉你，代码的哪些部分消耗了多少时间。Xdebug<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%B5%F7%CA%D4">调试</span>器包含了检验程序，评估检验总体上可以显示出代码的瓶颈。<br />
<br />
42.&nbsp; &nbsp; mod_gzip which is available as an Apache module compresses your data on the fly and can reduce the data to transfer up to 80%. mod_zip可作为Apache模块，用来即时压缩你的数据，并可让数据传输量降低80%。<br />
<br />
43.&nbsp; &nbsp; <a target="_blank" href="http://phplens.com/lens/php-book/optimizing-debugging-php.php">Excellent Article</a> （<a target="_blank" href="http://phplens.com/lens/php-book/optimizing-debugging-php.php">http://phplens.com/lens/php-book/optimizing-debugging-php.php</a>）about optimizing php by John Lim 另一篇优化PHP的精彩文章，由John Lim撰写.]]></description>
</item>
</channel>
</rss>