<?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/">
<channel>
<title>PHP5研究室</title>
        <image>
        <title>PHP5研究室 - 致力推广国内PHP发展!</title>
        <link>http://www.phpv.net/</link>
        <url>http://www.phpv.net/images/phpv_logo1.gif</url>
        </image>
<description>PHP5研究室 - PHP5研究室是提供PHP,mysql,linux,apache,WEB标准等精华文章的网站</description>
<managingEditor>easy@phpv.net</managingEditor> 
<webMaster>phpvcn@gmail.com</webMaster>
<link>http://www.phpv.net/</link>
<language>en</language>
<generator>Varticle 0.3</generator>

<item>
  <title>正则表达式权威中文手册(非官方)</title>
  <link>http://phpv.net/html/regular_expression.html</link>
  <comments>http://phpv.net/html/regular_expression.html#comments</comments>
  <pubDate>Wed, 07 May 2008 00:27:52 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ 非PHP技术话题 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/regular_expression.html</guid>
  <description><![CDATA[ 原来想写的PHP与正则表达系列教程,因为时间原因.没能持续。现在好了,有了这个手册.基本就全乎了.
这是我能看到的正则表达式相关文档中最易学实用，又最权威的一个．感谢deerchao同学的辛苦付出．点　&gt;&lt;a href=&quot;http://manual.phpv.net/regular_expression.html&quot; target=&quot;_blank&quot; title=&quot;正则表达式入门权威教程&quot;&gt;这里&lt;/a&gt;&lt;　可以看到． ]]></description>
  <content:encoded>
<![CDATA[ 原来想写的PHP与正则表达系列教程,因为时间原因.没能持续。现在好了,有了这个手册.基本就全乎了.<br>这是我能看到的正则表达式相关文档中最易学实用，又最权威的一个．感谢deerchao同学的辛苦付出．点　&gt;<a title="正则表达式入门权威教程" target="_blank" href="http://manual.phpv.net/regular_expression.html">这里</a>&lt;　可以看到．<br><br><br>－－－－－－－－－－－－－－－正文－－－－－－－－－－－－－－－－－<br><p>别被下面那些复杂的表达式吓倒，只要跟着我一步一步来，你会发现正则表达式其实并<span lang="zh-cn">没有</span>你
想像中的那么困难。当然，如果你看完了这篇教程之后，发现自己明白了很多，却又几乎什么都记不得，那也是很正常的——我认为，没接触过正则表达式的人在看
完这篇教程后，能把提到过的语法记住80%以上的可能性为零。这里只是让你明白基本的原理，以后你还需要多练习，多使用，才能熟练掌握正则表达式。</p>
    <p>除了作为入门教程之外，本文还试图成为可以在日常工作中使用的正则表达式语法参考手册。就作者本人的经历来说，这个目标还是完成得不错的——你看，我自己也没能把所有的东西记下来，不是吗？............更多点　&gt;<a title="正则表达式入门权威教程" target="_blank" href="http://manual.phpv.net/regular_expression.html">这里</a>&lt;　</p> ]]>
</content:encoded>
  </item>
<item>
  <title>如何为 MySQL 选择更合适的服务器硬件</title>
  <link>http://phpv.net/html/how_to_select_mysql_hardware.html</link>
  <comments>http://phpv.net/html/how_to_select_mysql_hardware.html#comments</comments>
  <pubDate>Fri, 02 May 2008 14:06:59 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ MYSQL数据库 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/how_to_select_mysql_hardware.html</guid>
  <description><![CDATA[ 用什么样的硬件做 MySQL ，真不是三言两语能说清楚的。DBA notes 的  Fenng 老大发了一篇为 MySQL 选择更合适的硬件的文章,我转摘过来,并根据自己的使用习惯做了点评.以下部分,红色字体为我的话. ]]></description>
  <content:encoded>
<![CDATA[ <p><a set="yes" linkindex="0" href="http://www.dbanotes.net/" accesskey="1">DBA notes</a> 的 <span class="byline"> <a style="color: orange;" set="yes" linkindex="19" href="http://www.dbanotes.net/">Fenng</a> 老大发了一篇</span><font size="2"><a set="yes" linkindex="8" href="http://www.dbanotes.net/database/mysql_hardware.html">为 MySQL 选择更合适的硬件</a></font><span class="byline">的文章,</span>我转摘过来,并根据自己的使用习惯做了点评.以下部分,红色字体为我的话.</p><p><br></p><p>-------------------------------------------- 分割线 ----------------------------------------</p><p><br></p><p>MySQL 爱好者关注的 <a linkindex="120" target="_blank" href="http://en.oreilly.com/mysql2008/public/content/home">2008 MySQL Conference &amp; Expo</a> 落幕后，很多文档都能看到了。今天读了一下这篇 <a set="yes" linkindex="121" target="_blank" href="http://en.oreilly.com/mysql2008/public/schedule/detail/2292">Scaling Out MySQL: Hardware Today and Tomorrow</a>。感兴趣的朋友也不防<a linkindex="122" target="_blank" href="http://www.scribd.com/doc/2569227/Scaling-out-MySQL-Hardware-today-and-tomorrow">下载</a>下来研究一下。</p>

<p>用什么样的硬件做 MySQL ，真不是三言两语能说清楚的。不过该讲座中还是能总结出来几点关键点的。</p>

<h4><br></h4><h4 style="color: rgb(0, 0, 205);"><font size="4">CPU 选择</font></h4>
<p>首先如有可能就<strong>选择 64 位CPU</strong>，这样才可以安装 64 位操作系统，有了 64 位操作系统才能利用好更大的内存。如果非要抬杠的话，不是 64 位芯片也可以安装 64 位操作系统，也就是 <a linkindex="123" target="_blank" href="http://www.dbanotes.net/review/intel_em64t_oracle.html">Intel 的 EM64T</a> 的解决方案(这也是文档中没提及的) 。</p>

<p>我个人倒是比较喜欢 AMD 64 位 CPU 的，物美价廉，性能也不错。</p>

<p>注意： MySQL 在多核上的 Bug 问题。</p><p><br></p><p>(<span style="color: rgb(255, 0, 0);">1.现在配置的服务器,基本上都是64位的CPU.</span><span style="color: rgb(255, 0, 0);">也许出于对稳定和系统兼容性的考虑,</span><span style="color: rgb(255, 0, 0);">很多管理员更喜欢安装32位的操作系统.我前段上线的一台53XX的四核至强CPU</span><span style="color: rgb(255, 0, 0);">服务器</span><span style="color: rgb(255, 0, 0);">,安装的是linux 64位操作系统[ubuntu server 8.0.4] 测试下来,在跑WEB服务这块,似乎没有任何稳定和软件兼容上的问题,大家可放心使用.</span></p><p><span style="color: rgb(255, 0, 0);">2.CPU个数,当然是双路或者四路最好.但如果压力不是非常巨大,我认为一颗CPU也够用了.省下的钱去换好的硬盘和加大内存,效果会更明显</span>)</p><h4><br></h4><h4 style="color: rgb(0, 0, 205);"><font size="4">内存，来者不拒</font></h4>

<p>第二点是尽可能配置比较大的内存，当然，只配置大内存如果 MySQL 参数配置有问题，还是摆设，如何设置各个引擎的 Cache 相关参数，够写一本书的了。</p>

<p>现在市场上内存是越来越便宜了。我个人的感觉内存降价的程度比 CPU 和硬盘都夸张很多。所以，考虑到人力越来越贵，内存越来越便宜，配置服务器的时候就别太吝啬了。</p><p><br></p><p>(<span style="color: rgb(255, 0, 0);">1. 这点几乎是共识了,个人推荐4G以上内存.参数配置和缓存设置方面我认为,一是别道听途说,自己多测试性能.按自己的实际情况调整参数. 二是认真看官方手册,手册的大多数,基本上算是真理了.</span>)<br></p>

<h4><br></h4><h4><br></h4><h4 style="color: rgb(0, 0, 205);"><font size="4">硬盘--唯快不破</font></h4>

<p>国内用 MySQL ，绝大多数都是直接仍在本机磁盘上的。这个磁盘的选择要慎重一点点。尽量选择 15K 而不要 10K
慢速磁盘，大多数数据库的磁盘问题都在速度上，如果只在磁盘上多花费 30%的钱而能得到总体性能的
30％收益，那么还是值得的，而容量多数情况下不会出现问题，现在的硬盘容量就是一个大。</p>

<p>至于选择什么类型的磁盘，SCSI 与 SAS 都可选，SATA 倒是够便宜，特定的应用再考虑吧。</p>

<p>这三板斧看是简单活，但是实际的应用场景下可未必就能做出更优的选择。最简单的东西也有人不知道不是?</p><p><br></p><p>(<span style="color: rgb(255, 0, 0);">是的,把CPU节省下来的钱,换上一块好的硬盘吧. 如果有需要,推荐部署单独的数据库服务器</span>)<br></p> ]]>
</content:encoded>
  </item>
<item>
  <title>PHP 5.2.6 发布</title>
  <link>http://phpv.net/html/PHP_5.2.6_update.html</link>
  <comments>http://phpv.net/html/PHP_5.2.6_update.html#comments</comments>
  <pubDate>Fri, 02 May 2008 12:56:58 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ PHP5研究[新] ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/PHP_5.2.6_update.html</guid>
  <description><![CDATA[ 五一劳动节,PHP5.2.6版本发布.修复4个安全方面的问题,把 PCRE 更新到了版本 7.6,同时还修复了130多处BUG

推荐有需要的用户更新. 点击进入可下载新版本及查看此PHP版本修复的BUG... ]]></description>
  <content:encoded>
<![CDATA[ 五一劳动节,PHP5.2.6版本发布. <br>修复4个安全方面的问题,把 PCRE 更新到了版本 7.6<br>同时还修复了130多处BUG<br><br>推荐有需要的用户更新.<br><br><a title="PHP5.2.6下载" target="_blank" href="http://cn2.php.net/get/php-5.2.6.tar.gz/from/cn.php.net/mirror">linux 系统点这里下载</a><br><a title="PHP5.2.5 WINDOWS系统安装包下载" target="_blank" href="http://cn.php.net/get/php-5.2.6-win32-installer.msi/from/this/mirror">WINDOWS安装包点这里下载</a>&nbsp;&nbsp; <a title="PHP5.2.6 zip解压包" target="_blank" href="http://cn2.php.net/get/php-5.2.6-Win32.zip/from/cn.php.net/mirror">WINDOWS ZIP 解压包版本点这里下载</a><br><br>需要其它版本,请到<a title="PHP官方网站下载" target="_blank" href="http://www.php.net/downloads.php">官方</a>去下载<br><br><br>以下是Version 5.2.6的ChangeLog:(英文)<br><br><ul><li>Security Fixes
		<ul><li>Fixed possible stack buffer overflow in FastCGI SAPI. (Andrei Nigmatulin)</li><li>Properly address incomplete multibyte chars inside escapeshellcmd() (Ilia, Stefan Esser)</li><li>Fixed security issue detailed in CVE-2008-0599. (Rasmus)</li><li>Fixed a safe_mode bypass in cURL identified by Maksymilian Arciemowicz. (Ilia)</li><li>Upgraded PCRE to version 7.6 (Nuno)</li></ul>
	</li><li>Fixed two possible crashes inside posix extension (Tony)</li><li>Fixed incorrect heredoc handling when label is used within the block.  (Matt)</li><li>Fixed sending of uninitialized paddings which may contain some information. (Andrei Nigmatulin)</li><li>Fixed a bug in formatting timestamps when DST is active in the default timezone (Derick)</li><li>Fix integer overflow in printf(). (Stas, Maksymilian Aciemowicz)</li><li>Fixed potential memleak in stream filter parameter for zlib filter. (Greg)</li><li>Added Reflection API metadata for the methods of the DOM classes. (Sebastian)</li><li>Fixed weird behavior in CGI parameter parsing. (Dmitry, Hannes Magnusson)</li><li>Fixed a bug with PDO::FETCH_COLUMN|PDO::FETCH_GROUP mode when a column # by which to group by data is specified. (Ilia)</li><li>Fixed segfault in filter extension when using callbacks. (Arnar Mar Sig, Felipe)</li><li>Fixed faulty fix for bug Fixed bug <a linkindex="11" href="http://bugs.php.net/40189">#40189</a> (endless loop in zlib.inflate stream filter). (Greg)</li><li>Fixed bug <a linkindex="12" href="http://bugs.php.net/44742">#44742</a> (timezone_offset_get() causes segmentation faults). (Derick)</li><li>Fixed bug <a set="yes" linkindex="13" href="http://bugs.php.net/44720">#44720</a> (Prevent crash within session_register()). (Scott)</li><li>Fixed bug <a linkindex="14" href="http://bugs.php.net/44703">#44703</a> (htmlspecialchars() does not detect bad character set argument). (Andy Wharmby)</li><li>Fixed bug <a linkindex="15" href="http://bugs.php.net/44673">#44673</a> (With CGI argv/argc starts from arguments, not from script) (Dmitry)</li><li>Fixed bug <a set="yes" linkindex="16" href="http://bugs.php.net/44667">#44667</a> (proc_open() does not handle pipes with the mode 'wb' correctly). (Jani)</li><li>Fixed bug <a linkindex="17" href="http://bugs.php.net/44663">#44663</a> (Crash in imap_mail_compose if "body" parameter invalid). (Ilia)</li><li>Fixed bug <a linkindex="18" href="http://bugs.php.net/44650">#44650</a> (escapeshellscmd() does not check arg count). (Ilia)</li><li>Fixed bug <a linkindex="19" href="http://bugs.php.net/44613">#44613</a> (Crash inside imap_headerinfo()). (Ilia, jmessa)</li><li>Fixed bug <a linkindex="20" href="http://bugs.php.net/44603">#44603</a> (Order issues with Content-Type/Length headers on POST). (Ilia)</li><li>Fixed bug <a linkindex="21" href="http://bugs.php.net/44594">#44594</a> (imap_open() does not validate # of retries parameter). (Ilia)</li><li>Fixed bug <a linkindex="22" href="http://bugs.php.net/44591">#44591</a> (imagegif's filename parameter). (Felipe)</li><li>Fixed bug <a linkindex="23" href="http://bugs.php.net/44557">#44557</a> (Crash in imap_setacl when supplied integer as username) (Thomas Jarosch)</li><li>Fixed bug <a linkindex="24" href="http://bugs.php.net/44487">#44487</a> (call_user_method_array issues a warning when throwing an exception). (David Soria Parra)</li><li>Fixed bug <a linkindex="25" href="http://bugs.php.net/44478">#44478</a> (Inconsistent behaviour when assigning new nodes). (Rob, Felipe)</li><li>Fixed bug <a linkindex="26" href="http://bugs.php.net/44445">#44445</a> (email validator does not handle domains starting/ending with a -). (Ilia)</li><li>Fixed bug <a linkindex="27" href="http://bugs.php.net/44440">#44440</a> (st_blocks undefined under BeOS). (Felipe)</li><li>Fixed bug <a linkindex="28" href="http://bugs.php.net/44394">#44394</a> (Last two bytes missing from output). (Felipe)</li><li>Fixed bug <a linkindex="29" href="http://bugs.php.net/44388">#44388</a> (Crash inside exif_read_data() on invalid images) (Ilia)</li><li>Fixed bug <a linkindex="30" href="http://bugs.php.net/44373">#44373</a> (PDO_OCI extension compile failed). (Felipe)</li><li>Fixed bug <a linkindex="31" href="http://bugs.php.net/44333">#44333</a> (SEGFAULT when using mysql_pconnect() with client_flags). (Felipe)</li><li>Fixed bug <a linkindex="32" href="http://bugs.php.net/44306">#44306</a> (Better detection of MIPS processors on Windows). (Ilia)</li><li>Fixed bug <a linkindex="33" href="http://bugs.php.net/44242">#44242</a> (metaphone('CMXFXM') crashes PHP). (Felipe)</li><li>Fixed bug <a linkindex="34" href="http://bugs.php.net/44233">#44233</a> (MSG_PEEK undefined under BeOS R5). (jonathonfreeman at gmail dot com, Ilia)</li><li>Fixed bug <a linkindex="35" href="http://bugs.php.net/44216">#44216</a> (strftime segfaults on large negative value). (Derick)</li><li>Fixed bug <a linkindex="36" href="http://bugs.php.net/44209">#44209</a> (strtotime() doesn't support 64 bit timestamps on 64 bit platforms). (Derick)</li><li>Fixed bug <a linkindex="37" href="http://bugs.php.net/44206">#44206</a> (OCI8 selecting ref cursors leads to ORA-1000 maximum open cursors reached). (Oracle Corp.)</li><li>Fixed bug <a linkindex="38" href="http://bugs.php.net/44200">#44200</a> (A crash in PDO when no bound targets exists and yet bound parameters are present). (Ilia)</li><li>Fixed bug <a linkindex="39" href="http://bugs.php.net/44197">#44197</a> (socket array keys lost on socket_select). (Felipe)</li><li>Fixed bug <a linkindex="40" href="http://bugs.php.net/44191">#44191</a> (preg_grep messes up array index). (Felipe)</li><li>Fixed bug <a linkindex="41" href="http://bugs.php.net/44189">#44189</a> (PDO setAttribute() does not properly validate values for native numeric options). (Ilia)</li><li>Fixed bug <a set="yes" linkindex="42" href="http://bugs.php.net/44184">#44184</a> (Double free of loop-variable on exception). (Dmitry)</li><li>Fixed bug <a linkindex="43" href="http://bugs.php.net/44171">#44171</a> (Invalid FETCH_COLUMN index does not raise an error). (Ilia)</li><li>Fixed bug <a linkindex="44" href="http://bugs.php.net/44166">#44166</a> (Parameter handling flaw in PDO::getAvailableDrivers()). (Ilia)</li><li>Fixed bug <a linkindex="45" href="http://bugs.php.net/44159">#44159</a> (Crash: $pdo-&gt;setAttribute(PDO::STATEMENT_ATTR_CLASS, NULL)). (Felipe)</li><li>Fixed bug <a linkindex="46" href="http://bugs.php.net/44152">#44152</a> (Possible crash with syslog logging on ZTS builds). (Ilia)</li><li>Fixed bug <a linkindex="47" href="http://bugs.php.net/44141">#44141</a> (private parent constructor callable through static function). (Dmitry)</li><li>Fixed bug <a linkindex="48" href="http://bugs.php.net/44113">#44113</a> (OCI8 new collection creation can fail with OCI-22303). (Oracle Corp.)</li><li>Fixed bug <a set="yes" linkindex="49" href="http://bugs.php.net/44069">#44069</a> (Huge memory usage with concatenation using . instead of .=). (Dmitry)</li><li>Fixed bug <a linkindex="50" href="http://bugs.php.net/44046">#44046</a> (crash inside array_slice() function with an invalid by-ref offset). (Ilia)</li><li>Fixed bug <a linkindex="51" href="http://bugs.php.net/44028">#44028</a> (crash inside stream_socket_enable_crypto() when enabling encryption without crypto type). (Ilia)</li><li>Fixed bug <a set="yes" linkindex="52" href="http://bugs.php.net/44018">#44018</a> (RecursiveDirectoryIterator options inconsistancy). (Marcus)</li><li>Fixed bug <a set="yes" linkindex="53" href="http://bugs.php.net/44008">#44008</a> (OCI8 incorrect usage of OCI-Lob-&gt;close crashes PHP). (Oracle Corp.)</li><li>Fixed bug <a linkindex="54" href="http://bugs.php.net/43998">#43998</a> (Two error messages returned for incorrect encoding for mb_strto[upper|lower]). (Rui)</li><li>Fixed bug <a linkindex="55" href="http://bugs.php.net/43994">#43994</a> (mb_ereg 'successfully' matching incorrect). (Rui)</li><li>Fixed bug <a set="yes" linkindex="56" href="http://bugs.php.net/43954">#43954</a> (Memory leak when sending the same HTTP status code multiple times). (Scott)</li><li>Fixed bug <a linkindex="57" href="http://bugs.php.net/43927">#43927</a> (koi8r is missing from html_entity_decode()). (andy at demos dot su, Tony)</li><li>Fixed bug <a linkindex="58" href="http://bugs.php.net/43912">#43912</a> (Interbase column names are truncated to 31 characters). (Ilia)</li><li>Fixed bug <a linkindex="59" href="http://bugs.php.net/43875">#43875</a> (Two error messages returned for $new and $flag argument in mysql_connect()). (Hannes)</li><li>Fixed bug <a linkindex="60" href="http://bugs.php.net/43863">#43863</a> (str_word_count() breaks on cyrillic "ya" in locale cp1251). (phprus at gmail dot com, Tony)</li><li>Fixed bug <a linkindex="61" href="http://bugs.php.net/43841">#43841</a> (mb_strrpos offset is byte count for negative values). (Rui)</li><li>Fixed bug <a linkindex="62" href="http://bugs.php.net/43840">#43840</a> (mb_strpos bounds check is byte count rather than a character count). (Rui)</li><li>Fixed bug <a linkindex="63" href="http://bugs.php.net/43808">#43808</a> (date_create never fails (even when it should)). (Derick)</li><li>Fixed bug <a linkindex="64" href="http://bugs.php.net/43793">#43793</a> (zlib filter is unable to auto-detect gzip/zlib file headers). (Greg)</li><li>Fixed bug <a linkindex="65" href="http://bugs.php.net/43703">#43703</a> (Signature compatibility check broken). (Dmitry)</li><li>Fixed bug <a linkindex="66" href="http://bugs.php.net/43677">#43677</a> (Inconsistent behaviour of include_path set with php_value). (manuel at mausz dot at)</li><li>Fixed bug <a linkindex="67" href="http://bugs.php.net/43663">#43663</a> (Extending PDO class with a __call() function doesn't work). (David Soria Parra)</li><li>Fixed bug <a linkindex="68" href="http://bugs.php.net/43647">#43647</a> (Make FindFile use PATH_SEPARATOR instead of ";"). (Ilia)</li><li>Fixed bug <a linkindex="69" href="http://bugs.php.net/43635">#43635</a> (mysql extension ingores INI settings on NULL values passed to mysql_connect()). (Ilia)</li><li>Fixed bug <a linkindex="70" href="http://bugs.php.net/43620">#43620</a> (Workaround for a bug inside libcurl 7.16.2 that can result in a crash). (Ilia)</li><li>Fixed bug <a linkindex="71" href="http://bugs.php.net/43614">#43614</a> (incorrect processing of numerical string keys of array in arbitrary serialized data). (Dmitriy Buldakov, Felipe)</li><li>Fixed bug <a linkindex="72" href="http://bugs.php.net/43606">#43606</a> (define missing depencies of the exif extension). (crrodriguez at suse dot de)</li><li>Fixed bug <a linkindex="73" href="http://bugs.php.net/43589">#43589</a> (a possible infinite loop in bz2_filter.c). (Greg)</li><li>Fixed bug <a linkindex="74" href="http://bugs.php.net/43580">#43580</a> (removed bogus declaration of a non-existent php_is_url() function). (Ilia)</li><li>Fixed bug <a linkindex="75" href="http://bugs.php.net/43559">#43559</a> (array_merge_recursive() doesn't behave as expected with duplicate NULL values). (Felipe, Tony)</li><li>Fixed bug <a linkindex="76" href="http://bugs.php.net/43533">#43533</a> (escapeshellarg('') returns null). (Ilia)</li><li>Fixed bug <a linkindex="77" href="http://bugs.php.net/43527">#43527</a> (DateTime created from a timestamp reports environment timezone). (Derick)</li><li>Fixed bug <a linkindex="78" href="http://bugs.php.net/43522">#43522</a> (stream_get_line() eats additional characters). (Felipe, Ilia, Tony)</li><li>Fixed bug <a linkindex="79" href="http://bugs.php.net/43507">#43507</a> (SOAPFault HTTP Status 500 - would like to be able to set the HTTP Status). (Dmitry)</li><li>Fixed bug <a linkindex="80" href="http://bugs.php.net/43505">#43505</a> (Assign by reference bug). (Dmitry)</li><li>Fixed bug <a linkindex="81" href="http://bugs.php.net/43498">#43498</a> (file_exists() on a proftpd server got SIZE not allowed in ASCII mode). (Ilia, crrodriguez at suse dot de)</li><li>Fixed bug <a linkindex="82" href="http://bugs.php.net/43497">#43497</a> (OCI8 XML/getClobVal aka temporary LOBs leak UGA memory). (Chris)</li><li>Fixed bug <a linkindex="83" href="http://bugs.php.net/43495">#43495</a> (array_merge_recursive() crashes with recursive arrays). (Ilia)</li><li>Fixed bug <a linkindex="84" href="http://bugs.php.net/43493">#43493</a> (pdo_pgsql does not send username on connect when password is not available). (Ilia)</li><li>Fixed bug <a linkindex="85" href="http://bugs.php.net/43491">#43491</a> (Under certain conditions, file_exists() never returns). (Dmitry)</li><li>Fixed bug <a linkindex="86" href="http://bugs.php.net/43483">#43483</a> (get_class_methods() does not list all visible methods). (Dmitry)</li><li>Fixed bug <a linkindex="87" href="http://bugs.php.net/43482">#43482</a> (array_pad() does not warn on very small pad numbers). (Ilia)</li><li>Fixed bug <a linkindex="88" href="http://bugs.php.net/43457">#43457</a> (Prepared statement with incorrect parms doesn't throw exception with pdo_pgsql driver). (Ilia)</li><li>Fixed bug <a linkindex="89" href="http://bugs.php.net/43450">#43450</a> (Memory leak on some functions with implicit object __toString() call). (David C.)</li><li>Fixed bug <a linkindex="90" href="http://bugs.php.net/43386">#43386</a> (array_globals not reset to 0 properly on init). (Ilia)</li><li>Fixed bug <a linkindex="91" href="http://bugs.php.net/43377">#43377</a> (PHP crashes with invalid argument for DateTimeZone). (Ilia)</li><li>Fixed bug <a linkindex="92" href="http://bugs.php.net/43373">#43373</a> (pcntl_fork() should not raise E_ERROR on error). (Ilia)</li><li>Fixed bug <a linkindex="93" href="http://bugs.php.net/43364">#43364</a> (recursive xincludes don't remove internal xml nodes properly). (Rob, patch from ddb@bitxtender.de)</li><li>Fixed bug <a linkindex="94" href="http://bugs.php.net/43301">#43301</a> (mb_ereg*_replace() crashes when replacement string is invalid PHP expression and 'e' option is used). (Jani)</li><li>Fixed bug <a linkindex="95" href="http://bugs.php.net/43295">#43295</a> (crash because of uninitialized SG(sapi_headers).mimetype). (Dmitry)</li><li>Fixed bug <a linkindex="96" href="http://bugs.php.net/43293">#43293</a> (Multiple segfaults in getopt()). (Hannes)</li><li>Fixed bug <a linkindex="97" href="http://bugs.php.net/43279">#43279</a> (pg_send_query_params() converts all elements in 'params' to strings). (Ilia)</li><li>Fixed bug <a linkindex="98" href="http://bugs.php.net/43276">#43276</a> (Incomplete fix for bug #42739, mkdir() under safe_mode). (Ilia)</li><li>Fixed bug <a linkindex="99" href="http://bugs.php.net/43248">#43248</a> (backward compatibility break in realpath()). (Dmitry)</li><li>Fixed bug <a linkindex="100" href="http://bugs.php.net/43221">#43221</a> (SimpleXML adding default namespace in addAttribute). (Rob)</li><li>Fixed bug <a linkindex="101" href="http://bugs.php.net/43216">#43216</a> (stream_is_local() returns false on "file://"). (Dmitry)</li><li>Fixed bug <a linkindex="102" href="http://bugs.php.net/43201">#43201</a> (Crash on using uninitialized vals and __get/__set). (Dmitry)</li><li>Fixed bug <a linkindex="103" href="http://bugs.php.net/43182">#43182</a> (file_put_contents() LOCK_EX does not work properly on file truncation). (Ilia)</li><li>Fixed bug <a linkindex="104" href="http://bugs.php.net/43175">#43175</a> (__destruct() throwing an exception with __call() causes segfault). (Dmitry)</li><li>Fixed bug <a linkindex="105" href="http://bugs.php.net/43128">#43128</a> (Very long class name causes segfault). (Dmitry)</li><li>Fixed bug <a linkindex="106" href="http://bugs.php.net/43105">#43105</a> (PHP seems to fail to close open files). (Hannes)</li><li>Fixed bug <a linkindex="107" href="http://bugs.php.net/43092">#43092</a> (curl_copy_handle() crashes with &gt; 32 chars long URL). (Jani)</li><li>Fixed bug <a linkindex="108" href="http://bugs.php.net/43003">#43003</a> (Invalid timezone reported for DateTime objects constructed using a timestamp). (Derick)</li><li>Fixed bug <a linkindex="109" href="http://bugs.php.net/42978">#42978</a> (mismatch between number of bound params and values causes a crash in pdo_pgsql). (Ilia)</li><li>Fixed bug <a linkindex="110" href="http://bugs.php.net/42945">#42945</a> (preg_split() swallows part of the string). (Nuno)</li><li>Fixed bug <a linkindex="111" href="http://bugs.php.net/42937">#42937</a> (__call() method not invoked when methods are called on parent from child class). (Dmitry)</li><li>Fixed bug <a linkindex="112" href="http://bugs.php.net/42841">#42841</a> (REF CURSOR and oci_new_cursor() crash PHP). (Chris)</li><li>Fixed bug <a linkindex="113" href="http://bugs.php.net/42838">#42838</a> (Wrong results in array_diff_uassoc) (Felipe)</li><li>Fixed bug <a linkindex="114" href="http://bugs.php.net/42779">#42779</a> (Incorrect forcing from HTTP/1.0 request to HTTP/1.1 response). (Ilia)</li><li>Fixed bug <a linkindex="115" href="http://bugs.php.net/42736">#42736</a> (xmlrpc_server_call_method() crashes). (Tony)</li><li>Fixed bug <a linkindex="116" href="http://bugs.php.net/42692">#42692</a> (Procedure 'int1' not present with doc/lit SoapServer). (Dmitry)</li><li>Fixed bug <a linkindex="117" href="http://bugs.php.net/42548">#42548</a> (mysqli PROCEDURE calls can't return result sets). (Hartmut)</li><li>Fixed bug <a linkindex="118" href="http://bugs.php.net/42505">#42505</a> (new sendmail default breaks on Netware platform) (Guenter Knauf)</li><li>Fixed bug <a linkindex="119" href="http://bugs.php.net/42369">#42369</a> (Implicit conversion to string leaks memory). (David C., Rob).</li><li>Fixed bug <a set="yes" linkindex="120" href="http://bugs.php.net/42272">#42272</a> (var_export() incorrectly escapes char(0)). (Derick)</li><li>Fixed bug <a set="yes" linkindex="121" href="http://bugs.php.net/42261">#42261</a> (Incorrect lengths for date and boolean data types). (Ilia)</li><li>Fixed bug <a linkindex="122" href="http://bugs.php.net/42190">#42190</a> (Constructing DateTime with TimeZone Indicator invalidates DateTimeZone). (Derick)</li><li>Fixed bug <a linkindex="123" href="http://bugs.php.net/42177">#42177</a> (Warning "array_merge_recursive(): recursion detected" comes again...). (Felipe)</li><li>Fixed bug <a linkindex="124" href="http://bugs.php.net/41941">#41941</a> (oci8 extension not lib64 savvy). (Chris)</li><li>Fixed bug <a linkindex="125" href="http://bugs.php.net/41828">#41828</a> (Failing to call RecursiveIteratorIterator::__construct() causes a sefault). (Etienne)</li><li>Fixed bug <a linkindex="126" href="http://bugs.php.net/41599">#41599</a> (setTime() fails after modify() is used). (Derick)</li><li>Fixed bug <a linkindex="127" href="http://bugs.php.net/41562">#41562</a> (SimpleXML memory issue). (Rob)</li><li>Fixed bug <a linkindex="128" href="http://bugs.php.net/40013">#40013</a> (php_uname() does not return nodename on Netware (Guenter Knauf)</li><li>Fixed bug <a linkindex="129" href="http://bugs.php.net/38468">#38468</a> (Unexpected creation of cycle). (Dmitry)</li><li>Fixed bug <a linkindex="130" href="http://bugs.php.net/32979">#32979</a> (OpenSSL stream-&gt;fd casts broken in 64-bit build) (stotty at tvnet dot hu)</li></ul><br> ]]>
</content:encoded>
  </item>
<item>
  <title>Ajax+PHP简单入门教程</title>
  <link>http://phpv.net/html/Ajax_PHP.htm</link>
  <comments>http://phpv.net/html/Ajax_PHP.htm#comments</comments>
  <pubDate>Fri, 14 Mar 2008 11:08:48 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ Web标准 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/Ajax_PHP.htm</guid>
  <description><![CDATA[ Ajax 由 HTML、JavaScript™ 技术、DHTML 和 DOM 组成，这一杰出的方法可以将笨拙的 Web 界面转化成交互性的 Ajax 应用程序。对于Ajax，最核心的一个对象是XMLHttpRequest，所有的Ajax操作都离不开对这个对象的操作。 ]]></description>
  <content:encoded>
<![CDATA[ <p>Ajax 由 HTML、JavaScript™ 技术、DHTML 和 DOM 组成，这一杰出的方法可以将笨拙的 Web
界面转化成交互性的 Ajax
应用程序。对于Ajax，最核心的一个对象是XMLHttpRequest，所有的Ajax操作都离不开对这个对象的操作。</p>
<p>首先我们来了解怎么在javascript中创建这个对象：</p>
<div><div><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">XMLHttpRequest</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></div></div>
<p>这行简单的代码在 Mozilla、Firefox、Safari、Opera 以及基本上所有以任何形式或方式支持 Ajax 的非 Microsoft 浏览器中，创建了 <code>XMLHttpRequest</code> 对象。但是对于市场占有率达到70%的IE来说，这种方法是不行的，而不同的IE版本还有不同的创建方法，所以我们需要在IE下面使用下面两种创建对象的办法：</p>
<div><div><span style="color: Green;">try</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ActiveXObject</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">Msxml2.XMLHTTP</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: rgb(255, 165, 0);">//针对较新的浏览器</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">err</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">try</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ActiveXObject</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">Microsoft.XMLHTTP</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: rgb(255, 165, 0);">//针对较老的浏览器</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">err2</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">false</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span></div></div>
<p>即使这样，我们也无法预料有些浏览器可能无法创建这个对象，所以在创建不成功的情况下，我们还要加上一句：</p>
<div><div><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">xmlHttp</span><span style="color: Olive;">){</span><span style="color: Gray;"><br></span><span style="color: Blue;">alert</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">无法创建 XMLHttpRequest 对象！</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span></div></div>
<p>结合起来就是：</p>
<div><div><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">false</span><span style="color: Gray;">;<br></span><span style="color: Green;">try</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">XMLHttpRequest</span><span style="color: Olive;">()</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">trymicrosoft</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">try</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ActiveXObject</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">Msxml2.XMLHTTP</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">othermicrosoft</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">try</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ActiveXObject</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">Microsoft.XMLHTTP</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">failed</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">false</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">xmlHttp</span><span style="color: Olive;">){</span><span style="color: Gray;"><br></span><span style="color: Blue;">alert</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">无法创建 XMLHttpRequest 对象！</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span></div></div>
<p>然后，让我们建立一个函数getInfo()，打开异步请求：</p>
<div><div><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">getInfo</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">num</span><span style="color: Gray;"> = </span><span style="color: Teal;">document</span><span style="color: Gray;">.</span><span style="color: Blue;">getElementById</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">num</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">.</span><span style="color: Blue;">value</span><span style="color: Gray;">;</span><span style="color: rgb(255, 165, 0);">//获得表单的数据</span><span style="color: Gray;"><br></span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">url</span><span style="color: Gray;"> = </span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">/ajax/1.php?n=</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;"> + </span><span style="color: Blue;">escape</span><span style="color: Olive;">(</span><span style="color: Blue;">num</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">open</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">GET</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;">, </span><span style="color: Blue;">url</span><span style="color: Gray;">, </span><span style="color: Green;">true</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: rgb(255, 165, 0);">//这里的true代表是异步请求</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span></div></div>
<p>一旦用 <code>open()</code> 配置好之后，就可以发送请求了。虽然可以使用 <code>send()</code> 发送数据，但也能通过 URL 本身发送数据。事实上，在大部分<code>GET</code> 请求中，用 URL 发送数据要容易得多，所以这里用null作为send()的参数就可以了。url地址里面的php文件是被请求来处理所需要数据的php文件，就像我们平时用PHP的时候一样，后面的参数可以加多个，并用&amp;分隔开来。</p>
<div><div><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">send</span><span style="color: Olive;">(</span><span style="color: Green;">null</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
<p>在发送了数据之后，我们需要用回调方法来获得服务器的状态，所以就用到了<code>onreadystatechange</code> 属性。</p>
<div><div><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">onreadystatechange</span><span style="color: Gray;"> = </span><span style="color: Blue;">updatePage</span><span style="color: Gray;">;</span></div></div>
<p>此语句已经要放在send()语句前面，这样才会有效，后面的updatePage是处理返回信息的一个函数。完整的getInfo()如下：</p>
<div><div><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">getInfo</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">num</span><span style="color: Gray;"> = </span><span style="color: Teal;">document</span><span style="color: Gray;">.</span><span style="color: Blue;">getElementById</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">num</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">.</span><span style="color: Blue;">value</span><span style="color: Gray;">;</span><span style="color: rgb(255, 165, 0);">//获得表单的数据</span><span style="color: Gray;"><br></span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">url</span><span style="color: Gray;"> = </span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">/ajax/1.php?n=</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;"> + </span><span style="color: Blue;">escape</span><span style="color: Olive;">(</span><span style="color: Blue;">num</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">open</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">GET</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;">, </span><span style="color: Blue;">url</span><span style="color: Gray;">, </span><span style="color: Green;">true</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: rgb(255, 165, 0);">//这里的true代表是异步请求</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">onreadystatechange</span><span style="color: Gray;"> = </span><span style="color: Blue;">updatePage</span><span style="color: Gray;">;<br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">send</span><span style="color: Olive;">(</span><span style="color: Green;">null</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span></div></div>
<p>我们还需要在html里面来触发这个函数：</p>
<div><div><span style="color: Olive;">&lt;</span><span style="color: Green;">input</span><span style="color: Gray;"> </span><span style="color: rgb(0, 0, 139);">name</span><span style="color: Gray;">=</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">num</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;"> </span><span style="color: rgb(0, 0, 139);">id</span><span style="color: Gray;">=</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">num</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;"> </span><span style="color: rgb(0, 0, 139);">onblur</span><span style="color: Gray;">=</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">getInfo()</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;"> </span><span style="color: rgb(0, 0, 139);">type</span><span style="color: Gray;">=</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">text</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;"> </span><span style="color: Olive;">/&gt;</span></div></div>
<p>下面我们需要来编写updatePage()这个函数：</p>
<div><div><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">updatePage</span><span style="color: Olive;">(){</span><span style="color: Gray;"><br></span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">xmlhttp</span><span style="color: Gray;">.</span><span style="color: Blue;">readyState</span><span style="color: Gray;"> == </span><span style="color: Maroon;">4</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">response</span><span style="color: Gray;"> = </span><span style="color: Blue;">xmlhttp</span><span style="color: Gray;">.</span><span style="color: Blue;">responseText</span><span style="color: Gray;">;<br></span><span style="color: Teal;">document</span><span style="color: Gray;">.</span><span style="color: Blue;">getElementById</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">city</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">.</span><span style="color: Blue;">value</span><span style="color: Gray;"> = </span><span style="color: Blue;">response</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span></div></div>
<p>上面这段代码里面的readyState是服务器返回的一个状态，4这个状态表示请求已经发送，并处理完毕。responseText是获得服务器返回的信息，然后通过javascript赋给ID为city的表单。</p>
<p>到此，一个简单的Ajax程序就完成了，完整的javascript代码如下：</p>
<div><div><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">false</span><span style="color: Gray;">;<br></span><span style="color: Green;">try</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">XMLHttpRequest</span><span style="color: Olive;">()</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">trymicrosoft</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">try</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ActiveXObject</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">Msxml2.XMLHTTP</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">othermicrosoft</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">try</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ActiveXObject</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">Microsoft.XMLHTTP</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"> </span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">failed</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;"> = </span><span style="color: Green;">false</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">xmlHttp</span><span style="color: Olive;">){</span><span style="color: Gray;"><br></span><span style="color: Blue;">alert</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">无法创建 XMLHttpRequest 对象！</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br>&nbsp;<br></span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">getInfo</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">num</span><span style="color: Gray;"> = </span><span style="color: Teal;">document</span><span style="color: Gray;">.</span><span style="color: Blue;">getElementById</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">num</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">.</span><span style="color: Blue;">value</span><span style="color: Gray;">;</span><span style="color: rgb(255, 165, 0);">//获得表单的数据</span><span style="color: Gray;"><br></span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">url</span><span style="color: Gray;"> = </span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">/ajax/1.php?n=</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;"> + </span><span style="color: Blue;">escape</span><span style="color: Olive;">(</span><span style="color: Blue;">num</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">open</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">GET</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Gray;">, </span><span style="color: Blue;">url</span><span style="color: Gray;">, </span><span style="color: Green;">true</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: rgb(255, 165, 0);">//这里的true代表是异步请求</span><span style="color: Gray;"><br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">onreadystatechange</span><span style="color: Gray;"> = </span><span style="color: Blue;">updatePage</span><span style="color: Gray;">;<br></span><span style="color: Blue;">xmlHttp</span><span style="color: Gray;">.</span><span style="color: Blue;">send</span><span style="color: Olive;">(</span><span style="color: Green;">null</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br>&nbsp;<br></span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">updatePage</span><span style="color: Olive;">(){</span><span style="color: Gray;"><br></span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">xmlhttp</span><span style="color: Gray;">.</span><span style="color: Blue;">readyState</span><span style="color: Gray;"> == </span><span style="color: Maroon;">4</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br></span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: Blue;">response</span><span style="color: Gray;"> = </span><span style="color: Blue;">xmlhttp</span><span style="color: Gray;">.</span><span style="color: Blue;">responseText</span><span style="color: Gray;">;<br></span><span style="color: Teal;">document</span><span style="color: Gray;">.</span><span style="color: Blue;">getElementById</span><span style="color: Olive;">(</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Red;">city</span><span style="color: rgb(139, 0, 0);">"</span><span style="color: Olive;">)</span><span style="color: Gray;">.</span><span style="color: Blue;">value</span><span style="color: Gray;"> = </span><span style="color: Blue;">response</span><span style="color: Gray;">;<br></span><span style="color: Olive;">}</span><span style="color: Gray;"><br></span><span style="color: Olive;">}</span></div></div>
<p>这里还缺一个php文件，由于处理的方式不一样，写法也不一样，而且这不是Ajax的主要部分，所以这里就不放代码了。只要记住php是输出并返回所需要的数据就可以了。</p><p><br></p><p>好久没更新,今天看到这教程,对初学者挺适合.<br></p> ]]>
</content:encoded>
  </item>
<item>
  <title>卡巴斯基7.0杀毒软件免费赠送一年激活码</title>
  <link>http://phpv.net/html/1593.html</link>
  <comments>http://phpv.net/html/1593.html#comments</comments>
  <pubDate>Thu, 31 Jan 2008 14:51:11 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ 非PHP技术话题 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1593.html</guid>
  <description><![CDATA[ 免费领取一年卡巴斯基7.0杀毒软件激活码的方法. ]]></description>
  <content:encoded>
<![CDATA[ 领取激活码方法:<br>1.打开 <a target="_blank" href="bbs.kaspersky.com.cn">bbs.kaspersky.com.cn</a> ,注册一个新帐户;<br>2.注册成功后,会把你导向到一个“大雪无情，卡巴有情”反病毒赠送活动页面;<br>3.在页面上输入你的正确邮箱地址，点提交！<br>4.去你的邮箱找一封由kaba365@pcstars.com.cn发给你的激活码邮件,按邮件提示就能领取到激活码了.<br><br><br>卡巴斯基7.0软件下载地址:<a target="_blank" href="http://www.kaspersky.com.cn/KL-Downloads/KL-Product7.0.htm">http://www.kaspersky.com.cn/KL-Downloads/KL-Product7.0.htm</a><br><br>注意事项:<br>每个电子邮件地址只能申请一个激活码，并请在收到激活码后<font color="red"><strong>两周内</strong></font>激活使用，过期将无法激活。<br>
港澳台地区及海外用户不能参加！<br> ]]>
</content:encoded>
  </item>
<item>
  <title>JavaScript程序编码规范 中文版</title>
  <link>http://phpv.net/html/1591.html</link>
  <comments>http://phpv.net/html/1591.html#comments</comments>
  <pubDate>Wed, 23 Jan 2008 15:08:05 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ 非PHP技术话题 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1591.html</guid>
  <description><![CDATA[ 所有的代码都要变成可供他人容易阅读的。编程规范可以帮助程序员们增加程序的健壮性。所有的 JavaScript 代码都是暴露给公众的。所以我们更应该保证其质量。保持整洁很重要。 ]]></description>
  <content:encoded>
<![CDATA[ <font size="4"><span style="font-weight: bold;">前言</span></font><br><br>Any violation to this guide is allowed if it enhances readability.<br><br><span style="color: rgb(255, 0, 0);">所有的代码都要变成可供他人容易阅读的。</span><br><br>软件的长期价值直接源于其编码质量。在它的整个生命周期里，一个程序可能会被许多人阅读或修改。如果一个程序可以清晰的展现出它的结构和特征，那就能减少在以后对其进行修改时出错的可能性。<br><br>编程规范可以帮助程序员们增加程序的健壮性。所有的 JavaScript 代码都是暴露给公众的。所以我们更应该保证其质量。保持整洁很重要。<br><br><font style="font-weight: bold;" size="4">JavaScript文件</font><br><br>JavaScript 程序应独立保存在后缀名为 .js 的文件中。<br><br>JavaScript 代码不应该被包含在 HTML 文件中，除非这是段特定只属于此部分的代码。在 HTML 中的JavaScript代码会明显增加文件大小，而且也不能对其进行缓存和压缩。<br><br>filename.js 应尽量放到 body 的后面。这样可以减少因为载入脚本而造成其他页面内容载入也被延迟的问题。也没有必要使用 language 或者 type 属性。MIME 类型是由服务器而非 scripttag 来决定的。（手气不错：个人认为按照 Web 标准而言，建议指定 type 属性，并将 &lt;script&gt; 放到页面的 &lt;head&gt; 中。）<br><br><font style="font-weight: bold;" size="4">缩进</font><br><br>缩进的单位为四个空格。避免使用 Tab 键来缩进。因为始终没有个统一的 Tab 长短标准。虽然使用空格会增加文件的大小，但在局域网中几乎可以忽略，且在最小化过程中也可被消除掉。<br><br><font size="4"><span style="font-weight: bold;">每行长度</span></font><br><br>避免每行超过 80 个字符。当一条语句一行写不下时，请考虑折行。在运算符号，最好是逗号后换行。在运算符后换行可以减少因为复制粘贴产生的错误被分号掩盖的几率。<br><br><font style="font-weight: bold;" size="4">注释</font><br><br>不要吝啬注释。给以后需要理解你的代码的人们（或许就是你自己）留下信息是非常有用的。注释应该和它们所注释的代码一样是书写良好且清晰明了。偶尔的小幽默就更不错了。记得要避免冗长或者情绪化。<br><br>及时地更新注释也很重要。错误的注释会让程序更加难以阅读和理解。<br><br>让注释有意义。重点在解释那些不容易立即明白的逻辑上。不要把读者的时间浪费在阅读类似于:<br><br>i = 0; // 让 i 等于 0<br><br>使用单行注释。块注释用于注释正式文档和无用代码。<br><br><font style="font-weight: bold;" size="4">变量声明</font><br><br>所有的变量必须在使用前进行声明。JavaScript 并不强制必须这么做，但这么做可以让程序易于阅读，且也容易发现那些没声明的变量(它们会被编译成全局变量)。<br><br>将 var 语句放在函数的首部。<br><br>最好把每个变量的声明语句单独放到一行，并加上注释说明。所有变量按照字母排序。<br><br>var currentEntry; // 当前选择项<br>var level; // 缩进程度<br>var size; // 表格大小<br><br>JavaScript 没有块范围，所以在块里面定义变量很容易引起 C/C++/Java 程序员们的误解。在函数的首部定义所有的变量。<br><br>尽量减少全局变量的使用。不要让局部变量覆盖全局变量。<br><font style="font-weight: bold;" size="4"><br>函数声明</font><br><br>所有的函数在使用前进行声明。 内函数的声明跟在 var 语句的后面。这样可以帮助判断哪些变量是在函数范围内的。<br><br>函数名与“(”（左括号）之间不应该有空格。“)”（右括号）与开始程序体的“{”（左大括号）之间应插入一个空格。函数程序体应缩进四个空格。“}”（右大括号）与声明函数的那一行代码头部对齐。<br><br>function outer(c，d) {<br>var e = c * d;<br><br>function inner(a， b) {<br>return (e * a) + b;<br>}<br><br>return inner(0， 1);<br>}<br><br>下面这种书写方式可以在 JavaScript 中正常使用，因为在 JavaScript 中，函数和对象的声明可以放到任何表达式允许的地方。且它让内联函数和混合结构具有最好的可读性。<br><br>function getElementsByClassName(className) {<br><br>var results = [];<br><br>walkTheDOM(document.body, function (node) {<br><br>var a; // array of class names<br><br>var c = node.className; // the node's classname<br><br>var i; // loop counter<br><br>// If the node has a class name, then split it into a list of simple names.<br><br>// If any of them match the requested name, then append the node to the set of results.<br><br>if (c) {<br><br>a = c.split(' ');<br><br>for (i = 0; i &lt; a.length; i += 1) {<br><br>if (a[i] === className) {<br><br>results.push(node);<br><br>break;<br><br>}<br><br>}<br><br>}<br><br>});<br><br>return results;<br><br>}<br><br><br><br>如果函数是匿名函数，则在 function 和 “(”（左括号）之间应有一个空格。如果省略了空格，否则会让人感觉函数名叫作 function。<br><br><br>div.onclick = function (e) {<br><br>return false;<br><br>};<br><br>that = {<br><br>method: function () {<br><br>return this.datum;<br><br>},<br><br>datum: 0<br><br>};<br><br>尽量不使用全局函数。<br><font style="font-weight: bold;" size="4"><br>命名</font><br><br>变量名应由 26 个大小写字母（A..Z，a..z），10 个数字（0..9），和 “_”（下划线）组成。避免使用国际化字符（如中文），因为它们不是在任何地方都可以被方便的阅读和理解。不要在命名中使用 “$”（美元符号）或者 “”（反斜杠）。<br><br>不要把 “_”（下划线）作为变量名的第一个字符。它有时用来表示私有变量，但实际上 JavaScript 并没提供私有变量的功能。如果私有变量很重要，那么使用 私有成员 的形式。应避免使用这种容易让人误解的命名习惯。<br><br>大多数的变量名和方法命应以小写字母开头。<br><br>必须与 new 共同使用的构造函数名应以大写字母开头。当 new 被省略时 JavaScript 不会有任何编译错误或运行错误抛出。忘记加 new 时会让不好的事情发生（比如被当成一般的函数），所以大写构造函数名是我们来尽量避免这种情况发生的唯一办法。<br><br>全局变量应该全部大写。（JavaScript 没有宏或者常量，所以不会因此造成误会）<br><font size="4"><br></font><font style="font-weight: bold;" size="4">语句<br><br></font><font style="color: rgb(0, 0, 205);" size="3">简单语句</font><br><br>每一行最多只包含一条语句。把 “,” （分号）放到每条简单语句的结尾处。注意一个函数赋值或对象赋值语句也是赋值语句，应该以分号结尾。<br><br>JavaScript 可以把任何表达式当作一条语句。这很容易隐藏一些错误，特别是误加分号的错误。只有在赋值和调用时，表达式才应被当作一条单独的语句。<br><font size="3"><br style="color: rgb(0, 0, 205);"><span style="color: rgb(0, 0, 205);">复合语句</span></font><br><br>复合语句是被包含在 “{ }”（大括号）的语句序列。<br><br>被括起的语句必须多缩进四个空格。<br><br>“{”（左大括号）应在复合语句其实行的结尾处。<br><br>“}”（右大括号）应与“{”（左大括号）的那一行的开头对齐。<br><br>大括号应该在所有复合语句中使用，即使只有一条语句，当它们是控制结构的一部分时，比如一个 if 或者 for 语句。这样做可以避免以后添加语句时造成的错误。<br><br><font style="font-weight: bold;" size="4">标示</font><br><br>语句标示是可选的，只有以下语句必须被标示：while、do、for、switch。<br><br><font size="3"><span style="color: rgb(0, 0, 205);">return 语句</span></font><br><br>一条有返回值的 return 语句不要使用“( )”（括号）来括住返回值。如果返回表达式，则表达式应与 return 关键字在同一行，以避免误加分号错误。<br><br><font style="color: rgb(0, 0, 205);" size="3">if 语句</font><br><br>if 语句应如以下格式:<br><br>if (condition){<br><br>statements;<br><br>}<br><br>if (condition) {<br><br>statements;<br><br>} else {<br><br>statements;<br><br>}<br><br>if (condition) {<br><br>statements;<br><br>} else if (condition) {<br><br>statements;<br><br>} else {<br><br>statements;<br><br>}<br><br><font style="color: rgb(0, 0, 205);" size="3">for 语句</font><br><br>for 语句应如以下格式:<br><br>for (initialization;condition; update) {<br><br>statements;<br><br>}<br><br><br><br>for (variable in object) if (filter) {<br><br>statements;<br><br>}<br><br>第一种形式的循环用于已经知道相关参数的数组循环。<br><br>第二种形式应用于对象中。Object 原型中的成员将会被包含在迭代器中。通过预先定义 hasOwnProperty方法来区分真正的 object 成员是个不错方法：<br><br>for (variablein object) if (object.hasOwnProperty(variable)){<br><br>statements;<br><br>}<br><br><font style="color: rgb(0, 0, 205);" size="3">while 语句</font><br><br>while 语句应如以下格式:<br><br>while (condition){<br><br>statements;<br><br>}<br><br><font style="color: rgb(0, 0, 205);" size="3">do 语句</font><br><br>do 语句应如以下格式:<br><br>do {<br><br>statements;<br><br>} while (condition);<br><br>不像别的复合语句，do 语句总是以 “;”（分号）结尾。<br><br><font style="color: rgb(0, 0, 205);" size="3">switch 语句</font><br><br>switch 语句应如以下格式:<br><br>switch (expression){<br><br>case expression:<br><br>statements;<br><br>default:<br><br>statements;<br><br>}<br><br>每个 case 与 switch 对齐。这可避免过分缩进。<br><br>每一组 statements（除了default 应以 break，return，或者 throw 结尾），不要让它顺次往下执行。<br><font style="color: rgb(0, 0, 205);" size="3"><br>try 语句</font><br><br>try 语句应如以下格式:<br><br>try {<br><br>statements;<br><br>} catch (variable){<br><br>statements;<br><br>}<br><br><br><br>try {<br><br>statements;<br><br>} catch (variable){<br><br>statements;<br><br>} finally {<br><br>statements;<br><br>}<br><br><font style="color: rgb(0, 0, 205);" size="3">continue 语句</font><br><br>避免使用 continue 语句。它很容易使得程序的逻辑过程晦涩难懂。<br>with 语句<br><br>不要使用 with 语句。<br><font style="color: rgb(0, 0, 205);" size="3"><br>空白</font><br><br>用空行来将逻辑相关的代码块分割开可以提高程序的可读性。空格应在以下情况时使用：<br><br>跟在“(”（左括号）后面的关键字应被一个空格隔开。<br><br><font style="color: rgb(0, 0, 205);" size="3">while (true) {</font><br><br>函数参数与“(”（左括号）之间不应该有空格。这能帮助区分关键字和函数调用。所有的二元操作符，除了“.”（点） 和“(”（左括号）和 “[”（左方括号）应用空格将其与操作数隔开。<br><br>一元操作符与其操作数之间不应有空格，除非操作符是个单词，比如 typeof。<br><br>每个在控制部分，比如 for 语句中的 “;”（分号）后须跟一个空格。<br><br>每个 “,”（逗号）后应跟一个空格。<br><font size="4"><br style="font-weight: bold;"><span style="font-weight: bold;">另外的建议</span></font><br><br><font style="color: rgb(148, 0, 211);" size="3">{} 和[]</font><br><br>使用 {} 代替 new Object()。使用 [] 代替 new Array() 。<br><br>当成员名是一组有序的数字时使用数组来保存数据。当成员名是无规律的字符串或其他时使用对象来保存数据。<br><br><font style="color: rgb(148, 0, 211);" size="3">，（逗号）操作符</font><br><br>避免使用逗号操作符，除非在特定的 for 语句的控制部分。（这不包括那些被用在对象定义，数组定义，var 语句，和参数列表中的逗号分隔符。）<br><br><font style="color: rgb(148, 0, 211);" size="3">作用域</font><br><br>在 JavaScript 中块没有域。只有函数有域。不要使用块，除非在复合语句中。<br><br><font style="color: rgb(148, 0, 211);" size="3">赋值表达式</font><br><br>避免在 if 和 while 语句的条件部分进行赋值。<br><br>if (a = b) {<br><br>是一条正确语句? 或者<br><br>if (a == b) {<br><br>才是对的? 避免这种不容易判断对错的结构。<br><br><font style="color: rgb(148, 0, 211);" size="3">=== 和 !== 操作符。</font><br><br>使用 === 和 !== 操作符会相对好点。== 和 != 操作符会进行类型强制转换。 特别是， 不要将 == 用于与错值比较（false，null，undefined，“”，0，NaN）。<br><font style="color: rgb(148, 0, 211);" size="3"><br>令人迷惑的加号和减号</font><br><br>小心在 + 后紧跟 + 或 ++。这种形式很容易仍人迷惑。应插入括号以便于理解。<br><br>total = subtotal + +myInput.value;<br><br>最好能写成<br><br>total = subtotal + (+myInput.value);<br><br>这样 + + 不会被误认为是 ++。<br><br><font style="color: rgb(148, 0, 211);" size="3">eval 是恶魔</font><br><br>eval 是 JavaScript 中最容易被滥用的方法。避免使用它。<br><br>eval 有别名。不要使用 function 构造器。不要给 setTimeout 或者 setInterval 传递字符串参数。<br><br><br>英文版：http://javascript.crockford.com/code.html<br>翻译:<a target="_blank" href="http://yeeyan.com/articles/view/cloudwater/4042">手气不错</a><br>整理日期：2008年01月22日<br><br> ]]>
</content:encoded>
  </item>
<item>
  <title>PHP与正则表达系列之一: PHP 中的正则表达式</title>
  <link>http://phpv.net/html/1590.html</link>
  <comments>http://phpv.net/html/1590.html#comments</comments>
  <pubDate>Mon, 14 Jan 2008 00:41:31 +0800</pubDate>
  <dc:creator>esayr</dc:creator>
<category>
<![CDATA[ PHP技术文档 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1590.html</guid>
  <description><![CDATA[ 今天起,会开始弄一个PHP教程系列文章. 主要是针对正则表达式的.
大概的内容排序是这样安排的:

1.  PHP 中的正则表达式
2.  八个实用的PHP正则表达式
3.  如何书写更易阅读的PHP正则表达式
4.  半小时精通正则表达式
5.  正则在文章采集系统中的应用及常见问题答疑
6.  ...更多策划中

文章内容来源方面,有本站旧文重新整理而来,也有翻译英文文献而来(感谢在加拿大的!oEL同学),还有些是个人心得.
个人能力有限,肯定有一些错误,发现的朋友请给予提醒以及时更正. 不至误导新手. 如果文章能给大家一些参考,就很满足了. 也欢迎PHP爱好者投稿,完善本系列,让新手少走一些弯路. ]]></description>
  <content:encoded>
<![CDATA[ 今天起,会开始弄一个PHP教程系列文章. 主要是针对正则表达式的.<br>大概的内容排序是这样安排的:<br><br>1.&nbsp; PHP 中的正则表达式<br>2.&nbsp; 八个实用的PHP正则表达式<br>3.&nbsp; 如何书写更易阅读的PHP正则表达式<br>4.&nbsp; 半小时精通正则表达式<br>5.&nbsp; 正则在文章采集系统中的应用及常见问题答疑<br>6.&nbsp; ...更多策划中<br><br>文章内容来源方面,有本站旧文重新整理而来,也有翻译英文文献而来(感谢在加拿大的!oEL同学),还有些是个人心得.<br>个人能力有限,肯定有一些错误,发现的朋友请给予提醒以及时更正. 不至误导新手. 如果文章能给大家一些参考,就很满足了. 也欢迎PHP爱好者<a title="投稿" target="_blank" href="http://www.phpv.net/html/submit.html">投稿</a>,完善本系列,让新手少走一些弯路. <br><br><br><br style="color: rgb(255, 0, 0);"><span style="font-weight: bold; color: rgb(255, 0, 0);">PHP与正则表达系列之: PHP 中的正则表达式</span><br><br><br>

                                
                                                                                
            
             
                <h3>正则表达式简介及正则表达式在PHP中的作用</h3>正
则表达式是一种表示规则的途经，在 PHP 中利用这些规则可以让你灵活变通地<span style="color: rgb(255, 0, 0); font-weight: bold;">匹配</span>、<span style="color: rgb(255, 0, 0); font-weight: bold;">检验</span>、<span style="color: rgb(255, 0, 0); font-weight: bold;">替换</span>以及<span style="font-weight: bold; color: rgb(255, 0, 0);">修改</span><span style="color: rgb(0, 0, 205); font-weight: bold;"> 字符串</span>。本文涉及到 PCRE
的基础，以及如何使用 preg_match()，preg_replace()，and preg_split()
函数。<br><br>接下来就让我们从实例循序渐进地开始学习如何使用这些函数。<br>
<div class="serendipity_entry_extended"><h3>规则匹配 preg_match</h3>利用 preg_match()，我们可以完成字符串的规则匹配。如果找到一个匹配，preg_match() 函数返回 1，否则返回 0。还有一个可选的第三参数可以让你把匹配的部分存在一个数组中。在验证数据时这个功能可以变得非常有用。<br>
<blockquote>$string = "football";<br>
if (preg_match('/foo/', $string)) {<br>
	// 匹配正确<br>
}</blockquote><br>上面的例子将成功匹配，因为单词 football 里面包含 foo。现在我们来试一个更复杂的，例如验证一个 Email 地址。<br>
<blockquote>$string = "first.last@domain.uno.dos";<br>
if (preg_match(<br>
'/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',<br>
$string)) {<br>
	// 验证Email地址<br>
}</blockquote><br>这个例子将验证出此 Email 地址为正确格式。现在让我们来看看这段正则表达式所代表的各种规则。<br>
<br>
<br>PCRE 顾名思义，与在 Perl 中的正则表达式有相同的语法，所以每段正则表达式必须要有一对定界符。我们一般使用 <b>/</b> 为定界符。<br>
<br>开头的 <b>^</b> 和结尾的 <b>$</b> 让PHP从字符串开头检查到结尾。假使没有 $，程序仍会匹配到 Email 的末尾。<br>
<br>
<b>[</b> 和 <b>]</b> 被用来限制许可输入类型。例如 a-z 允许所有的小写字母，A-Z 允许所有的大写字母，0-9 所有数字，等等，以及更多其他类型。 <br>
<br>
<b>{</b> 和 <b>}</b> 被用来限制期望的字符数。例如 {2,4} 表示字符串的每一节可以有 2-4 字符长度，像是 .com.cn 或 .info。在这里, "<b>.</b>" 并不算一个字符，因为 {2,4} 之前定义的许可输入类型只有大小写字母，故此段只匹配大小写字母<br>
<br>
 <b>(</b> 和 <b>)</b> 被用来合并小节，并定义字符串中必须存在的字符。(a|b|c) 能够匹配 a 或 b 或 c。<br>
<br>(<b>.</b>) 将匹配所有字符，而 [.] 只匹配 "<b>.</b>" 本身。<br>
<br>要使用一些符号本身，必须在前增加一个 <b></b>。这些字符有：<b>( ) [ ] . * ? + ^ | $</b><br>
<h3>规则替换 preg_replace</h3> preg_replace 允许你替换字符串中匹配到你定义的正则表达式。一个简单的注释移除功能：<br><br style="color: rgb(0, 0, 205);"><span style="color: rgb(255, 0, 0);">preg_replace('[(/*)+.+(*/)]', '', $val);</span><br><br>这段代码可以移除在 PHP 和 CSS 中使用 /* 注释 */ 格式的多多行注释。其中的三个参数分别为<b>正则表达式</b>，要替换成的字符串和要替换的目标字符串（这里要做移除功能，所以是个空白字符串 -&gt; ''）。如果你想匹配次级规则，可以使用 $0 代表全部匹配，$1、$2 等，以此类推代表分别的次级规则。<br>
<h3>规则分割preg_split</h3>preg_split 可以将整段字符串按匹配到的正则表达式分割成 1、2或更多字符的多段。比如获取标签，无论是用空格还是逗号分隔的：<br>
<blockquote>$tags = preg_split('/[,]/', 'my,tags,unevenly,spaced');<br>
print_r($tags);</blockquote><br>正则表达式是一个很实用的技巧，让你可以专注于所期望得到的内容。<br><br>但有时候一段正则表达式并不能让你如愿以偿得到预期的结果是件很烦人的事，所以我将在本系列的第二篇文章附上一些简单的语法指南希望能够帮到大家。<br><br>如果你想跳过痛苦的练习过程而直接获得一些成功的喜悦感，请期待<a href="http://www.phpv.net">PHP5研究室</a>推出的 "PHP与正则表达系列之二: 八个实用PHP正则表达式"。<br>
<br><br>
<h3>附:PCRE 语法指南<br></h3>
<b>/</b> 定界符<br>
<b>^</b> 字符串头<br>
<b>$</b> 字符串尾<br>
<b>[a-z]</b> 所有小写字母<br>
<b>[A-Z]</b> 所有大写字母<br>
<b>[0-9]</b> 所有数字<br>
<b>?</b> 零或一个紧接前的字符<br>
<b>*</b> 零或多个紧接前的字符<br>
<b>+</b> 一或多个紧接前的字符<br>
<b>{4}</b> 4个紧接前的字符<br>
<b>{4,8}</b> 4-8个紧接前的字符<br>
<b>.</b> 任意字符<br>
<b>(red|green|blue)</b> Red 或 green 或 blue（红 或 绿 或 蓝）<br>
<b>s</b> 空格<br>
<b><br>特殊字符（需要在前加 ）</b><br>
<b>(   )   [   ]   .   *   ?   +   ^   |   $</b></div><br><br> ]]>
</content:encoded>
  </item>
<item>
  <title>PHP 4.4.8发布</title>
  <link>http://phpv.net/html/1589.html</link>
  <comments>http://phpv.net/html/1589.html#comments</comments>
  <pubDate>Sun, 06 Jan 2008 01:31:20 +0800</pubDate>
  <dc:creator>admin</dc:creator>
<category>
<![CDATA[ PHP技术文档 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1589.html</guid>
  <description><![CDATA[ 　　PHP开发小组近日发布了PHP 4.4.8。和之前的版本一样，这次发布依然是以改进4.4系统的安全性和稳定性为主，官方建议用户尽可能升级。由于这次的发布包括了PHP 4.4系列主要的补丁，所以可能会是最多一个正式的PHP 4.4发行版。但是，以后如果要解决一些安全漏洞的话，也可能继续发布修订版，直至2008年08月08日。 ]]></description>
  <content:encoded>
<![CDATA[ 　　PHP开发小组近日发布了PHP
4.4.8。和之前的版本一样，这次发布依然是以改进4.4系统的安全性和稳定性为主，官方建议用户尽可能升级。由于这次的发布包括了PHP
4.4系列主要的补丁，所以可能会是最多一个正式的PHP
4.4发行版。但是，以后如果要解决一些安全漏洞的话，也可能继续发布修订版，直至2008年08月08日。<br><br>　　PHP 4.4.8中主要的安全改进：<br>
<ul><li>改进了MOPB-02-2007的补丁</li><li>修正了chunk_split()函数内部的整数溢出问题</li><li>修正了str[c]spn()函数内部的整数溢出问题</li><li>修正了因#41655导致的当open_basedir开启时的全局回归问题</li><li>修正了money_format()不能接受多个%i或%n参数的问题</li><li>向php.ini中添加了max_input_nesting_level指令，用于限制输入数据的嵌套层数</li><li>修正了MySQL处理INFILE LOCAL选项的行为，当open_basedir或safe_mode开启时，该选项会被禁用</li><li>修正了session.save_path和error_log会忽略open_basedir和safe_mode</li></ul>
<br>　　更详细的更新列表，可参见PHP 4.4.8的<a target="_blank" href="http://cn.php.net/ChangeLog-4.php#4.4.8">ChangeLog</a><br><br>　　下载地址：<a target="_blank" style="font-weight: bold;" href="http://cn.php.net/downloads.php#v4">http://cn.php.net/downloads.php#v4</a><img src="http://blog.donews.com/phpor/aggbug/1243450.aspx" height="1" width="1"><br><br><br>昨天看到英文版的,就知道今天刘铭会出这个公告.果然等到了.<br> ]]>
</content:encoded>
  </item>
<item>
  <title>Web开发设计的五大准则</title>
  <link>http://phpv.net/html/1588.html</link>
  <comments>http://phpv.net/html/1588.html#comments</comments>
  <pubDate>Wed, 02 Jan 2008 23:39:55 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ Web标准 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1588.html</guid>
  <description><![CDATA[ 如果仓促而为，设计一个专题或者网站一定会成为恶梦。Web设计需要遵循一些准则并有计划地去做。规则一:先出设计图...... ]]></description>
  <content:encoded>
<![CDATA[ <p>如果仓促而为，设计一个专题或者网站一定会成为恶梦。Web设计需要遵循一些准则并有计划地去做。</p>
<p style="font-weight: bold; color: rgb(255, 0, 0);">规则 #1 : 先出设计图</p>
<p>这是必须的。不要假设设计图在你的头脑中就开始设计web，必须要放到纸上。可以这样做：</p>
<p>1，&nbsp; 拿尺子、笔和纸，按照具体的尺寸一行一行地画下来；</p>
<p>2，&nbsp; 记得考虑分界线的长度等，这样才能符合CSS的像素；</p>
<p>3，&nbsp; 记下设计的每一个细节免得忘记，如果把所有细节都累积到最后将是巨大的麻烦。</p>
<p style="font-weight: bold; color: rgb(255, 0, 0);">规则 #2 :配色</p>
<p>这是设计的核心部分，只有颜色搭配合适才能使你的网页看起来不错。首先要决定的是主色，也即你在网页中多数使用的颜色；然后选择跟主色调搭配的第二颜色；不要选择超过三种颜色不然你的设计看起来会很乱。如果你想要更多的颜色，可以使用浅色或者深色的阴影来搭配主色调。</p>
<p>1，&nbsp; 浏览十个跟你网页有同样主色调的网页；</p>
<p>2，&nbsp; 给几个人看你的配色方案并取得反馈；</p>
<p>3，&nbsp; 从浏览的网页和反馈你将更好地完善你的颜色搭配。</p>
<p style="font-weight: bold; color: rgb(255, 0, 0);">规则 #3 : 从基本的版块开始构建</p>
<p>定下配色和设计图之后，从最基本的框架开始构建——我的意思是说不添加任何文本。因为在版面中加入文本会使得架构混乱。方法如下：</p>
<p>1，&nbsp; 每一个版块设定边界线，这样能够看到具体的尺寸和位置；</p>
<p>2，&nbsp; 对不同的版块使用不同的颜色，在完成版块后再改成你想要的颜色。</p>
<p style="font-weight: bold; color: rgb(255, 0, 0);">规则 #4 : 理清CSS</p>
<p>不要在你的HTML文件中将styling元素搞得太复杂，不然等到你修改的时候你就不得不到处搜索。所以将所有styling元素归置在一个单独的CSS文档中。</p>
<p>在styling之前理清你的CSS免得太过杂乱导致你多次重复同一件事。CSS支持继承，也即parent
block的style可以用于child
block.，充分利用这条特性。命名CSS分类名也要易懂易记。比如使用“main_content”而不是“div_1”。</p>
<p style="color: rgb(255, 0, 0); font-weight: bold;">规则 #5 : 制订多重 CSS 文档</p>
<p>我们都知道，使用浏览器可以轻易地看到网页的输出，但使用另一浏览器的时候则可能发现输出不正常。这不是什么稀奇事儿，因为每个浏览器对HTML和CSS的处理方式都不一样。</p>
<p>为避免这种情况，每个浏览器准备一个CSS文档，这样所有浏览器都可以正常浏览。虽然这有一定的难度，但是记着指望一个CSS文档来满足所有浏览器是不可能的。</p><br><p><br></p><p>原文作者：nitinpai<br>原文链接：<a target="_blank" href="http://techtracer.com/2007/12/10/5-rules-for-a-good-web-design/">5 Rules For A Good Web Design</a><br>译者：<a target="_blank" href="http://www.yeeyan.com/space/show/6559">小猪哥</a></p> ]]>
</content:encoded>
  </item>
<item>
  <title>我的PHP编码规范</title>
  <link>http://phpv.net/html/my_PHP_Coding_Standard.html</link>
  <comments>http://phpv.net/html/my_PHP_Coding_Standard.html#comments</comments>
  <pubDate>Mon, 24 Dec 2007 17:54:48 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ PHP技术文档 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/my_PHP_Coding_Standard.html</guid>
  <description><![CDATA[ esayr个人的PHP编码规范,仅供参考. ]]></description>
  <content:encoded>
<![CDATA[ 以下是我个人的PHP编码规范,仅供参考,欢迎拍砖.<br><br>最后更新:2007-10-17 <font color="#ff0000"><b><br>
<br>
PHP文件夹/文件命名规范</b></font><br>
-----------------------------------<br>
<ul><li>
    为方便和兼容不同操作系统,PHP文件夹/文件名统一全部使用<span style="background-color: rgb(255, 0, 0);">小写</span>,需要时可用下划线.
  </li><li>
    类文件,取名方式: <font color="#3366ff">功能.class.php</font> 如
    <font color="#3366ff">db_mysql.class.php</font>
  </li><li>
    函数文件取名 <font color="#3366ff">功能.fun.inc.php</font> 如
    <font color="#3366ff">news.fun.inc.php</font>
  </li><li>
    不能通过浏览器直接访问的php文件取名 <font color="#3366ff">**.inc.php</font>
    并记得在第一行加入如下限制代码<font color="#ff0000"><br>
    !defined('INIT_PHPV') &amp;&amp; die('Denied');&nbsp; <br></font></li></ul>
<font color="#3333ff"><br><span style="color: rgb(0, 0, 0);">注意:以上规范,<i>不适用于</i> 网上下载的类库文件.</span><br><br>
</font> <font color="#3333ff">常用的文件夹有:</font><br>
<ol><li>
    admin&nbsp; <font color="#c0c0c0">/管理</font><br>
  </li><li>
    images <font color="#c0c0c0">/图片</font><br>
  </li><li>
    templates <font color="#c0c0c0">/模板</font><br>
  </li><li>
    includes <font color="#c0c0c0">/包含文件,各种函数及类库</font><br>
  </li><li>
    script&nbsp; <font color="#c0c0c0">/前台脚本和css</font><br>
  </li><li>
    data&nbsp; <font color="#c0c0c0">/网站数据 此文件夹可写. 内有缓存文件,错误日志等</font><br>
  </li><li>
    upload <font color="#c0c0c0">/上传文件夹</font><br>
  </li><li>
    html <font color="#c0c0c0">/静态html目录</font><br>
    <br>
    <font color="#ff0000"><br style="font-weight: bold;">
    </font>
  </li></ol>
<font color="#ff0000"><b>PHP代码书写规范</b></font><br>
-------------------------<br><br>
<br>
类名: 单词间首字母用大写,其它小写.如 class <b>MySql </b>{.... }<br>
<font color="#3366ff"> 类中的方法</font>命名规范同上.<br>
<br>
函数命名:<br>
驼峰形式.即首单词字母小写,其它大写如<br>
<font color="#cc33cc"> function </font><font color="#cc33cc">error ($msg) {...}<br>
function </font><font color="#cc33cc">sendMail ($email) {..}</font><br>
<br>
变量也使用驼峰形式.如<font color="#cc33cc"><br>
$fileName = 'abc.txt';</font><br>
<br>
sql语句则遵照标准写法<br>
关键字大写,表名和字段名最好用``引起来.查询参数用单引号引起来 如<br>
<font color="#cc33cc"> $DB-&gt;Query("SELECT * FROM `tablename' WHERE `uid'='1'
");</font><br>
<br>
if...else用法:<br>
统一使用大括号,除非非常特殊的情况下,不能用 <font color="#ff0000"><u>endif;</u></font><br>
<br>
大括号用法:<br>
推荐用&nbsp;<br>
<font color="#cc33cc">function foo {<br>
&nbsp;&nbsp; ....<br>
}</font><br>
<br>
也可用<br>
<font color="#cc33cc">function foo<br>
{<br>
&nbsp;&nbsp; ....<br>
}</font><br>
<br>
<br>
在PHP文件里,除了语言包注释配置文件,其它地方不能有中文.<br>
所有文件,保存格式为UTF8<br>
<br>
<br>
<font color="#ff0000"><b> 数据库命名规范</b></font><br>
-------------------------<br>
表名全小写,如果需要,用下划线隔开单词<br>
字段名单词首字母大写<br>
如: 表user字段UserName<br>
<br>
<br>
<br> ]]>
</content:encoded>
  </item>
<item>
  <title>在linux上配置 PHP+PDO-MSSQL 心得</title>
  <link>http://phpv.net/html/1586.html</link>
  <comments>http://phpv.net/html/1586.html#comments</comments>
  <pubDate>Mon, 10 Dec 2007 12:50:36 +0800</pubDate>
  <dc:creator>esayr</dc:creator>
<category>
<![CDATA[ PHP安装配置 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1586.html</guid>
  <description><![CDATA[ 本文介绍了在linux下配置PHP以支持pdo-mssql 的方法. WIN下用PHP读写MSSQL很简单,装上MSSQL客户端,再编辑PHP.INI开个扩展extension=php_mssql.dll ,就OK了. PDO的支持也是如此: extension=php_pdo_mssql.dll ]]></description>
  <content:encoded>
<![CDATA[ WIN下用PHP读写MSSQL很简单,装上MSSQL客户端,再编辑PHP.INI开个扩展extension=php_mssql.dll ,就OK了. PDO的支持也是如此: extension=php_pdo_mssql.dll<br><br>可是linux下就不是那么简单的事情.<br>有过linux下读写MSSQL数据库经验的朋友,对于freetds这个东西肯定不陌生. 配置相对也不复杂:<br><br><b>先到<a href="http://www.freetds.org/" target="_blank">http://www.freetds.org/</a>下载 源码包</b><br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">代码:</div><pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 470px; height: 50px; text-align: left;">$ cd /tmp<br>$ wget<a href="ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz" target="_blank">ftp://ftp.ibiblio.org/pub/Linux/ALPH...tds-stable.tgz</a></pre></div><b>解压并安装</b><br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">代码:</div><pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 470px; height: 114px; text-align: left;">$ tar zxvf freetds-stable.tgz<br>$ ./configure --prefix=/usr/local/freetds<br>$ make<br>$ su root<br>Password:<br>$ make install</pre></div><b>然后编译PHP</b><br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">代码:</div><pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 470px; height: 98px; text-align: left;">$cd ../php-5.2.5<br>$./configure --prefix=/usr/local/php <br>--with-apxs2=/usr/local/apache/bin/apxs <br>.... 其它参数 <br>--with-mssql=/usr/local/freetds</pre></div>(也可以用 --with-sybase=/usr/local/freetds)<br><br><b>make 并 make install</b><br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">代码:</div><pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 470px; height: 82px; text-align: left;">$ make<br>$ su root<br>Password:<br># make install</pre></div><b>配置</b><b>freetds</b><br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">代码:</div><pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 470px; height: 34px; text-align: left;"># vim /usr/local/freetds/etc/freetds.conf</pre></div>找到类似的行<br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">代码:</div><pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 470px; height: 98px; text-align: left;"># A typical Microsoft SQL Server 7.0 configuration<br>;[MyServer70]<br>;        host = 192.168.0.1<br>;        port = 1433<br>;        tds version = 7.0</pre></div>把他们前面的冒号删除,把host改为你的MSSQL服务器主机名或IP地址.port改为自己的端口号,<br>tds version是SQLserver的版本,2000的是7.0 要是其它的版本,自己查查.<br><br>注意:[<font color="#ff0000">MyServer70</font>] 非常重要. 将会在PHP代码中代替 mssql_connect("host","sa",""); 中的 host<br>关于freetds的其它如 ODBC/tsql/ 配置,请参考<a href="http://www.freetds.org/userguide/" target="_blank">http://www.freetds.org/userguide/</a><br><b>好了,完成后重启WEB服务. PHPINFO里看看,应该有如图的信息:<br><span style="text-decoration: underline;"><img alt="" src="http://www.phpv.net/uploadfile/month_200712/phpinfo_mssql_phpv_1.jpg" align="" border="0"></span><br><br>再用如下代码测试:</b><br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">PHP 代码:</div><div class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 470px; height: 194px; text-align: left;"><code style="white-space: nowrap;"><!--php buffer start--><code><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 187);">&lt;?php<br>$conn</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(0, 0, 187);">mssql_connect</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(221, 0, 0);">"MyServer70"</span><span style="color: rgb(0, 119, 0);">,</span><span style="color: rgb(221, 0, 0);">"sa"</span><span style="color: rgb(0, 119, 0);">,</span><span style="color: rgb(221, 0, 0);">"password"</span><span style="color: rgb(0, 119, 0);">);<br></span><span style="color: rgb(0, 0, 187);">mssql_select_db</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(221, 0, 0);">'dbname'</span><span style="color: rgb(0, 119, 0);">,</span><span style="color: rgb(0, 0, 187);">$conn</span><span style="color: rgb(0, 119, 0);">);<br></span><span style="color: rgb(0, 0, 187);">$msquery</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(221, 0, 0);">"select&nbsp;firstname,lastname&nbsp;from&nbsp;table"</span><span style="color: rgb(0, 119, 0);">;<br></span><span style="color: rgb(0, 0, 187);">$msresults</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(0, 0, 187);">mssql_query</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(0, 0, 187);">$msquery</span><span style="color: rgb(0, 119, 0);">);<br>while&nbsp;(</span><span style="color: rgb(0, 0, 187);">$row</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(0, 0, 187);">mssql_fetch_array</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(0, 0, 187);">$msresults</span><span style="color: rgb(0, 119, 0);">))&nbsp;{<br>echo<br></span><span style="color: rgb(221, 0, 0);">"&lt;li&gt;"</span><span style="color: rgb(0, 119, 0);">.<br></span><span style="color: rgb(0, 0, 187);">$row</span><span style="color: rgb(0, 119, 0);">[</span><span style="color: rgb(221, 0, 0);">'titleofcourtesy'</span><span style="color: rgb(0, 119, 0);">]&nbsp;.</span><span style="color: rgb(221, 0, 0);">"&nbsp;"</span><span style="color: rgb(0, 119, 0);">.</span><span style="color: rgb(0, 0, 187);">$row</span><span style="color: rgb(0, 119, 0);">[</span><span style="color: rgb(221, 0, 0);">'firstname'</span><span style="color: rgb(0, 119, 0);">]&nbsp;.</span><span style="color: rgb(221, 0, 0);">"&nbsp;"</span><span style="color: rgb(0, 119, 0);">.</span><span style="color: rgb(0, 0, 187);">$row</span><span style="color: rgb(0, 119, 0);">[</span><span style="color: rgb(221, 0, 0);">'lastname'</span><span style="color: rgb(0, 119, 0);">]&nbsp;.</span><span style="color: rgb(221, 0, 0);">"&lt;/li&gt;n"</span><span style="color: rgb(0, 119, 0);">;<br>}<br></span><span style="color: rgb(0, 0, 187);">?&gt;</span></span></code><!--php buffer end--></code></div></div>库和表存在并有数据.应该会返回正确的数据了.<br>如果有问题,查查配置文件是否正常,MSSQL服务器有没有开远程连接,防火墙等等.<br><br><br>到这里,MSSQL是可以用了.但感觉很不爽,PDO应该是PHP以后的标准.所以现在来搞定PDO-MSSQL:<br><br>因为有pdo-mysql配置经验,开始时我想当然的在编译PHP5时直接加参数--with-pdo-mssql=/usr/local/freetds<br>结果./configure时系统返回一个错误.<br><br>通过查看./configure --help 才知道,需要通过dblib来做.<br><br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">代码:</div><pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 470px; height: 226px; text-align: left;">$cd ../php-5.2.5<br>$./configure --prefix=/usr/local/php <br>--with-apxs2=/usr/local/apache/bin/apxs <br>.... 其它参数 <br>--enable-pdo <br>--with-pdo-sqlite<br>--with-pdo-mysql=/usr/local/mysql/bin/mysql_config <br>--with-mssql=/usr/local/freetds<br>--with-pdo-dblib=//usr/local/freetds<br>$ make<br>$ su root<br>Password:<br># make install</pre></div>重启apache 刷新phpinfo页面.多了这一项表示成功:<br><br><span style="text-decoration: underline;"><img alt="" src="http://www.phpv.net/uploadfile/month_200712/phpinfo_pdo_mssql_phpv_1.jpg" align="" border="0"></span><br><br>老习惯,代码验证:<br><div style="margin: 5px 20px 20px;"><div class="smallfont" style="margin-bottom: 2px;">PHP 代码:</div><div class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 550px; height: 450px; text-align: left;"><code style="white-space: nowrap;"><!--php buffer start--><code><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 187);">&lt;?php<br><br></span><span style="color: rgb(0, 119, 0);">try&nbsp;{<br><br></span><span style="color: rgb(0, 0, 187);">$hostname</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(221, 0, 0);">'192.168.0.1'</span><span style="color: rgb(0, 119, 0);">;</span><span style="color: rgb(255, 128, 0);">//注意,这里和上面不同,要直接用IP地址或主机名<br></span><span style="color: rgb(0, 0, 187);">$port</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(0, 0, 187);">1433</span><span style="color: rgb(0, 119, 0);">;</span><span style="color: rgb(255, 128, 0);">//端口<br></span><span style="color: rgb(0, 0, 187);">$dbname</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(221, 0, 0);">"dbname"</span><span style="color: rgb(0, 119, 0);">;</span><span style="color: rgb(255, 128, 0);">//库名<br></span><span style="color: rgb(0, 0, 187);">$username</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(221, 0, 0);">"sa"</span><span style="color: rgb(0, 119, 0);">;</span><span style="color: rgb(255, 128, 0);">//用户<br></span><span style="color: rgb(0, 0, 187);">$pw</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(221, 0, 0);">"password"</span><span style="color: rgb(0, 119, 0);">;</span><span style="color: rgb(255, 128, 0);">//密码<br></span><span style="color: rgb(0, 0, 187);">$dbh</span><span style="color: rgb(0, 119, 0);">=&nbsp;new</span><span style="color: rgb(0, 0, 187);">PDO</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(221, 0, 0);">"dblib:host=$hostname:$port;dbname=$dbname"</span><span style="color: rgb(0, 119, 0);">,</span><span style="color: rgb(221, 0, 0);">"$username"</span><span style="color: rgb(0, 119, 0);">,</span><span style="color: rgb(221, 0, 0);">"$pw"</span><span style="color: rgb(0, 119, 0);">);<br>}&nbsp;catch&nbsp;(</span><span style="color: rgb(0, 0, 187);">PDOException&nbsp;$e</span><span style="color: rgb(0, 119, 0);">)&nbsp;{<br>echo</span><span style="color: rgb(221, 0, 0);">"Failed&nbsp;to&nbsp;get&nbsp;DB&nbsp;handle:&nbsp;"</span><span style="color: rgb(0, 119, 0);">.</span><span style="color: rgb(0, 0, 187);">$e</span><span style="color: rgb(0, 119, 0);">-&gt;</span><span style="color: rgb(0, 0, 187);">getMessage</span><span style="color: rgb(0, 119, 0);">()&nbsp;.</span><span style="color: rgb(221, 0, 0);">"n"</span><span style="color: rgb(0, 119, 0);">;<br>exit;<br>}<br><br>echo</span><span style="color: rgb(221, 0, 0);">'connent&nbsp;MSSQL&nbsp;succeed'</span><span style="color: rgb(0, 119, 0);">;<br><br></span><span style="color: rgb(0, 0, 187);">$stmt</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(0, 0, 187);">$dbh</span><span style="color: rgb(0, 119, 0);">-&gt;</span><span style="color: rgb(0, 0, 187);">prepare</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(221, 0, 0);">"select&nbsp;firstname,lastname&nbsp;from&nbsp;table"</span><span style="color: rgb(0, 119, 0);">);<br></span><span style="color: rgb(0, 0, 187);">$stmt</span><span style="color: rgb(0, 119, 0);">-&gt;</span><span style="color: rgb(0, 0, 187);">execute</span><span style="color: rgb(0, 119, 0);">();<br>while&nbsp;(</span><span style="color: rgb(0, 0, 187);">$row</span><span style="color: rgb(0, 119, 0);">=</span><span style="color: rgb(0, 0, 187);">$stmt</span><span style="color: rgb(0, 119, 0);">-&gt;</span><span style="color: rgb(0, 0, 187);">fetch</span><span style="color: rgb(0, 119, 0);">())&nbsp;{<br></span><span style="color: rgb(0, 0, 187);">print_r</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(0, 0, 187);">$row</span><span style="color: rgb(0, 119, 0);">);<br>}<br>unset(</span><span style="color: rgb(0, 0, 187);">$dbh</span><span style="color: rgb(0, 119, 0);">);&nbsp;unset(</span><span style="color: rgb(0, 0, 187);">$stmt</span><span style="color: rgb(0, 119, 0);">);<br><br></span><span style="color: rgb(0, 0, 187);">?&gt;</span></span></code><!--php buffer end--></code></div></div>输出正常..搞定!<br><br><span style="color: rgb(255, 0, 0);">2008.05.06更新:</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">如果读出来是乱码,请试试在/usr/local/freetds/etc/freetds.conf中找到[global]</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">在下面加一行</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">client charset = utf8</span><br style="color: rgb(255, 0, 0);"><br><br> ]]>
</content:encoded>
  </item>
<item>
  <title>取代squid的高性能开源HTTP加速器Varnish配置教程</title>
  <link>http://phpv.net/html/varnish.htm</link>
  <comments>http://phpv.net/html/varnish.htm#comments</comments>
  <pubDate>Sat, 08 Dec 2007 22:37:56 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ linux学习 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/varnish.htm</guid>
  <description><![CDATA[ varnish是一款高性能的开源HTTP加速器，挪威最大的在线报纸 Verdens Gang (http://www.vg.no) 使用3台Varnish代替了原来的12台squid，性能居然比以前更好。 ]]></description>
  <content:encoded>
<![CDATA[ &nbsp;varnish是一款高性能的开源HTTP加速器，挪威最大的在线报纸 Verdens Gang (<a target="_blank" href="http://www.vg.no%29/">http://www.vg.no)</a> 使用3台Varnish代替了原来的12台squid，性能居然比以前更好。<br><br>varnish
的作者Poul-Henning
Kamp是FreeBSD的内核开发者之一，他认为现在的计算机比起1975年已经复杂许多。在1975年时，储存媒介只有两种：内存与硬盘。但现在计算
机系统的内存除了主存外，还包括了cpu内的L1、L2，甚至有L3快取。硬盘上也有自己的快取装置，因此squid
cache自行处理物件替换的架构不可能得知这些情况而做到最佳化，但操作系统可以得知这些情况，所以这部份的工作应该交给操作系统处理，这就是
Varnish cache设计架构。<br><br><br>安装配置教程:<br><br>1.下载源码包编译安装：<br><br>cd /usr/local/src &amp;&amp; wget <a target="_blank" href="http://nchc.dl.sourceforge.net/sourceforge/varnish/varnish-1.1.1.tar.gz">http://nchc.dl.sourceforge.net/sourceforge/varnish/varnish-1.1.1.tar.gz</a><br>tar zxvf /usr/local/src/varnish-1.1.1.tar.gz<br>cd /usr/local/src/varnish-1.1.1<br>./autogen.sh<br>./configure --enable-debugging-symbols --enable-developer-warnings --enable-dependency-tracking<br><br>注：如果你的gcc版本是4.2.0或更高的版本，可以加上--enable-extra-warnings编译参数，在出错时，得到附加的警告信息。<br>我
这里是用源码包安装的，如果你是redhat或centos可以用rpm包来安装<br><br><br>2. 建立cache目录：<br><br>mkdir -p /cache/varnish/V&nbsp;&nbsp;&amp;&amp; chown -R nobody:nobody /cache <br><br>3.编写启动文件:<br><br>cd /usr/local/varnish/sbin<br>vi start.sh<br><br>内容如下：<br>#!/bin/sh<br># file: start.sh<br>date -u<br>/usr/local/varnish/sbin/varnishd \<br>-a 10.0.0.129:80 \<br>-s file,/cache/varnish/V,1024m \<br>-f /usr/local/varnish/sbin/vg.vcl.default \<br>-p thread_pool_max=1500 \<br>-p thread_pools=5 \<br>-p listen_depth=512 \<br>-p client_http11=on \<br><br>注：-a 是指定后端服务器的ip或hostname，就象squid做revese proxy时的originserver.<br><br>不过这个也可以在vcl里面写。<br>-f 是指定所用的vcl的文件。<br>-s 指定cache目录的存储类型，文件位置和大小。<br>-p 是指定varnish的启动的一些启动参数，可以根据自己的机器配置来优化varnish的性能。<br>其他参数已经参数的具体含义可以用varnishd --help 来查看。<br><br>4.编写vcl：<br><br>我的vcl如下：<br><br>backend default {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set backend.host = "127.0.0.1";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set backend.port = "http";<br>}<br><br>#我用的是一台机器做测试，使用的backend用的是127.0.0.1:80.如果varnish机器和后台的机器分开的。<br>写上对应的机器的ip或hostname就可以了。<br><br>sub vcl_recv {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (req.request != "GET" &amp;&amp; req.request != "HEAD") {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pipe;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (req.http.Expect) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pipe;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (req.http.Authenticate || req.http.Cookie) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pass;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (req.request == "GET" &amp;&amp; req.url ~ "\.(gif|jpg|swf|css|js)$") {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lookup;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lookup;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>sub vcl_pipe {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pipe;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>sub vcl_pass {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pass;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>sub vcl_hash {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>sub vcl_hit {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!obj.cacheable) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pass;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deliver;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>sub vcl_timeout {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discard;<br>}<br><br>sub vcl_discard {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discard;<br>}<br><br>如果是多个站点在不同的originserver时，可以使用下面配置：<br><br>backend www {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set backend.host = "www.abc.com";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set backend.port = "80";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>backend images {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set backend.host = "images.abc.com";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set backend.port = "80";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>sub vcl_recv {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (req.http.host ~ "^(<a target="_blank" href="http://www.%29/?jackbillow.com$">www.)?abc.com$</a>") {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set req.http.host = "www.abc.com";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set req.backend = www;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} elsif (req.http.host ~ "^images.abc.com$") {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set req.backend = images;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error 404 "Unknown virtual host";<br>}<br><br>5.启动varnish：<br><br>/usr/local/varnish/sbin/start.sh<br><br>Mon Sep&nbsp;&nbsp;3 03:13:19 UTC 2007<br>file /cache/varnish/V/varnish.tEKXXx (unlinked) size 1073741824 bytes (262144 fs-blocks, 262144 pages)<br>Using old SHMFILE<br><br>ps waux | grep varnish <br>root&nbsp;&nbsp;&nbsp;&nbsp; 16254&nbsp;&nbsp;0.0&nbsp;&nbsp;0.0 11200&nbsp;&nbsp;708 ? Ss&nbsp;&nbsp; 10:43&nbsp;&nbsp; 0:00 /usr/local/varnish/sbin/varnishd -a 10.0.0.129:80 -s /varnish/V,1024m <br><br>-f /usr/local/varnish/sbin/vg.vcl.default -p thread_pool_max 1500 -p thread_pools 5 -p listen_depth 512 -p client_http11 on<br>nobody&nbsp;&nbsp; 16255&nbsp;&nbsp;0.0&nbsp;&nbsp;0.1 1152552 1808 ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sl&nbsp;&nbsp; 10:43&nbsp;&nbsp; 0:00 /usr/local/varnish/sbin/varnishd -a 10.0.0.129:80 -s <br><br>file,/cache/varnish/V,1024m -f /usr/local/varnish/sbin/vg.vcl.default -p thread_pool_max 1500 -p thread_pools 5 -p <br><br>listen_depth 512 -p client_http11 on<br><br>看到上面信息说明varnish正确启动，恭喜你，你已经配置成功了。<br><br><br>------------------------<br>本文转自<span class="entry-source-title-parent"><a href="http://www.google.com/reader/view/feed/http%3A%2F%2Ffeed.feedsky.com%2Fleftleg" class="entry-source-title" target="_blank">Leftleg's Blog</a>,为阅读方便,有部分增删.</span> ]]>
</content:encoded>
  </item>
<item>
  <title>基于apache mod_vhost_alias模块的虚拟主机配置教程</title>
  <link>http://phpv.net/html/1584.html</link>
  <comments>http://phpv.net/html/1584.html#comments</comments>
  <pubDate>Mon, 26 Nov 2007 00:20:57 +0800</pubDate>
  <dc:creator>admin</dc:creator>
<category>
<![CDATA[ linux学习 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1584.html</guid>
  <description><![CDATA[ 前言:我有几台服务器托在机房,连年亏损. 我想我应该考虑将他们向外出租.准备明年运营,以扭转几年来尴尬的局面.于是,就有了这个教程. ]]></description>
  <content:encoded>
<![CDATA[ <br>前言:我有几台服务器托在机房,连年亏损. 我想我应该考虑将他们向外出租.准备明年运营,以扭转几年来尴尬的局面.于是,就有了这个教程.<br><br><span style="font-weight: bold;">目标:<br><br></span><span style="color: rgb(255, 0, 0);">1.用户开通FTP后,自动在/www/下创建一个与域名同名的目录.</span><br><span style="color: rgb(0, 0, 205);">(假如phpv.net的管理员购买空间后,他的主目录将是 /www/phpv.net)</span><br><span style="color: rgb(255, 0, 0);">2.空间知道泛域名绑定.</span><br><span style="color: rgb(0, 0, 205);">(即:访问者在浏览器内输入www.phpv.net将会自动访问/www/phpv.net/www.phpv.net目录下的index文件.而输入bbs.phpv.net则访问/www/phpv.net/bbs.phpv.net/这个目录</span>.....)<br><br><br>按以前的,我得挨个绑虚拟主机.然后再restart apache<br>像这样:<br><br><span style="font-style: italic;">&lt;VirtualHost *:80&gt;</span><br style="font-style: italic;"><span style="font-style: italic;">&nbsp;&nbsp;&nbsp; ServerAdmin webmaster@phpv.net</span><br style="font-style: italic;"><span style="font-style: italic;">&nbsp;&nbsp;&nbsp; DocumentRoot /www/phpv.net/www.phpv.net</span><br style="font-style: italic;"><span style="font-style: italic;">&nbsp;&nbsp;&nbsp; ServerName www.phpv.net</span><br style="font-style: italic;"><span style="font-style: italic;">&nbsp;&nbsp;&nbsp; ErrorLog logs/phpv-error_log</span><br style="font-style: italic;"><span style="font-style: italic;">&nbsp;&nbsp;&nbsp; CustomLog logs/phpv-access_log common</span><br style="font-style: italic;"><span style="font-style: italic;">&lt;/VirtualHost&gt;</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;">&lt;VirtualHost *:80&gt;</span><br style="font-style: italic;"><span style="font-style: italic;">
&nbsp;&nbsp;&nbsp; ServerAdmin webmaster@phpv.net</span><br style="font-style: italic;"><span style="font-style: italic;">
&nbsp;&nbsp;&nbsp; DocumentRoot /www/phpv.net/bbs.phpv.net</span><br style="font-style: italic;"><span style="font-style: italic;">
&nbsp;&nbsp;&nbsp; ServerName bbs.phpv.net</span><br style="font-style: italic;"><span style="font-style: italic;">
&nbsp;&nbsp;&nbsp; ErrorLog logs/bbs-phpv-error_log</span><br style="font-style: italic;"><span style="font-style: italic;">
&nbsp;&nbsp;&nbsp; CustomLog logs/bbs-phpv-access_log common</span><br style="font-style: italic;"><span style="font-style: italic;">
&lt;/VirtualHost&gt;</span><br><br>...............<br><br> #apache restart<br><br>简直太烦人太累了.<br><br>后来经过自己的测试和多位好友的帮助,我使用Apache 的 mod_vhost_alias模块.完美实现了这个要求.<br><br><br style="font-weight: bold;"><span style="font-weight: bold;">我是这样开始的:</span><br><br><span style="color: rgb(30, 144, 255);">1.把原来的虚拟主机配置都删除掉, NameVirtualHost *:80 这句也加上个#在它前面.</span><br><br style="color: rgb(30, 144, 255);"><span style="color: rgb(30, 144, 255);">2.接着,在httpd.conf使用下面的mod_vhost_alias配置</span><br><br style="font-style: italic;"><span style="font-style: italic;">UseCanonicalName Off</span><br style="font-style: italic;"><span style="font-style: italic;">VirtualDocumentRoot /www/%2+/%0</span><br><br>(注意:以上<span style="font-style: italic;">/www/</span>是我的网站根目录,在实现操作中请按自己要求更改.)<br><br>重启apache.<br>#apache restart<br><br><span style="color: rgb(30, 144, 255);">3.测试</span><br>&nbsp;&nbsp; 使用FTP服务器的功能,使得用户登录时,自动以其域名创建主目录.(我用的是 pureftpd 具体配置请参阅相关文献)&nbsp;&nbsp; <br>&nbsp;&nbsp; 以刚刚创建好的FTP用户登录,在目录下创建文件夹www.phpv.net 上传一个phpinfo的index.php<br>&nbsp;&nbsp; 输入http://www.phpv.net 看看是否正常. (域名的A记录要指向本机IP) 如果能正常显示出info信息,就表明成功了.<br><br><span style="color: rgb(30, 144, 255);">4.但,问题来了,使用http://phpv.net 访问的却是 /www/net/</span><span style="color: rgb(30, 144, 255);">phpv.net</span><span style="color: rgb(30, 144, 255);">这个目录.</span><br>想使用rewirte做一个自动跳转来解决这个问题,使得用户输入http://phpv.net时能访问到/www/phpv.net/www.phpv.net 这个目录 <br><br>rewirte解决方式:<br><br>加以下rule到http.conf中<br><br>RewriteEngine On<br>#RewriteCond %{HTTP_HOST} ^w+.w{1,3}$<br>RewriteCond %{HTTP_HOST} ^[a-z-0-9]+.w{1,3}$RewriteRule (.*) http://www.%{HTTP_HOST}$1 [R=301,L]<br><br><br>再次重启Apache,访问http://phpv.net,自动跳转到http://www.phpv.net<br><br><br><span style="color: rgb(30, 144, 255);">5.相关问答:</span><br>如果把不需要执行PHP的目录禁用PHP解析?<br><br>这样:<br>&lt;Directory "/www/phpv.net/manual.phpv.net"&gt;<br>php_flag engine off<br>&lt;/Directory&gt;<br><br>好了.配置基本OK.<br><br>感谢:fluck boban 吴洪声 对本文的贡献.<br><br>附后:此配置基本能满足大部分用户的需求.<br>但有以下缺点:不能根据虚拟主机做个性化设置,比如,设置一个虚拟主机的PHP执行目录范围.<br>还有不能自动绑定两个域名到同一目录.<br> ]]>
</content:encoded>
  </item>
<item>
  <title>MySQL  Proxy - MySQL代理的介绍及个人使用经验</title>
  <link>http://phpv.net/html/1583.html</link>
  <comments>http://phpv.net/html/1583.html#comments</comments>
  <pubDate>Sun, 25 Nov 2007 01:54:44 +0800</pubDate>
  <dc:creator>esayr</dc:creator>
<category>
<![CDATA[ MYSQL数据库 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1583.html</guid>
  <description><![CDATA[ 收到Mysql AB的邮件, 看到 Mysql Proxy 这个东西发布的时候,我很兴奋.
因为当时我在弄一个项目,需要网通和电信两个镜像站点同时读写一个布署在电信服务器上的mysql数据库.中间有台双线的服务器可以做数据中转,试过很多方案都不理想.
Mysql Proxy很好的解决了我的问题.虽然目前还是测试版,可直到现在三个月,这个业务一直很稳定的在运行着. ]]></description>
  <content:encoded>
<![CDATA[ 收到Mysql AB的邮件, 看到 Mysql Proxy 这个东西发布的时候,我很兴奋.<BR>因为当时我在弄一个项目,需要网通和电信两个镜像站点同时读写一个布署在电信服务器上的mysql数据库.中间有台双线的服务器可以做数据中转,试过很多方案都不理想.<BR><BR>Mysql Proxy很好的解决了我的问题.虽然目前还是测试版,可到现在三个月了,我的这个业务一直很稳定的在运行着.<BR><BR>下面就介绍一下当时的情况:<BR><BR>目的很明确,在下面的图片中,我仅希望web server 3(网通线路)的服务器能快速读写Data base server中的数据.<BR><BR><PRE class=programlisting><SPAN class=postbody><IMG alt="" src="http://www.phpv.net/uploadfile/month_200711/mysql_proxy_phpv_1.jpg" border=0></SPAN></PRE><BR><BR>但由于"<A href="http://www.google.com/search?q=%E4%B8%96%E7%95%8C%E4%B8%8A%E6%9C%80%E9%81%A5%E8%BF%9C%E7%9A%84%E8%B7%9D%E7%A6%BB%E4%B8%8D%E6%98%AF...%E8%80%8C%E6%98%AF%E4%B8%AD%E5%9B%BD%E7%94%B5%E4%BF%A1%E5%88%B0%E4%B8%AD%E5%9B%BD%E7%BD%91%E9%80%9A&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=org.mozilla:en-US:official&amp;client=firefox-a" target=_blank>世界上最遥远的距离不是...而是中国电信到中国网通</A>" 这个中国特色的问题,我从web server 3到Data base server 的ping 值在夜间闲时都在300ms以上,所以,通过第一种走法(蓝色).基本上网通的镜像慢得等于没用.<BR><BR>还好,我有台双线服务器托管在双线机房,它可以比较快速的连接Data base server和web server 3. 但这台服务器在跑其它重要业务,只能做数据中转.<BR><BR>最后.我在web server 2 (双线路) 上安装了Mysql proxy. 当web server 3需要连接 Data base server 的数据库时,只需要连接双线服务器的网通IP(红线走法),就OK了.<BR><BR>那什么是Mysql proxy 呢?<BR><IMG alt="" src="http://www.phpv.net/uploadfile/month_200711/local_ufAzLpzSbJ.jpg" border=0><BR><BR><BR>MySQL代理是一个介于MySQL客户端和MySQL服务器之间的简单程序，可用来监视、分析或者传输他们之间的通讯。他的灵活性允许你最大限度的使用它，这些包括负载平衡、容错 、分析查询和修正等等。官方网址是:<A href="http://forge.mysql.com/wiki/MySQL_Proxy" target=_blank>http://forge.mysql.com/wiki/MySQL_Proxy</A><BR><BR>我在<A class="external free" title=http://dev.mysql.com/downloads/mysql-proxy/ href="http://dev.mysql.com/downloads/mysql-proxy/" rel=nofollow>http://dev.mysql.com/downloads/mysql-proxy/</A>下载了linux系统平台下的 MySQL proxy alpha 编译好的二进制版本.<BR><BR>解压,然后复制到/usr/local/sbin下,就开始可以使用了.(如果下的是源码,,则需要make一下)<PRE class=programlisting>$ tar zxf<EM class=replaceable><CODE>mysql-proxy-0.5.0.tar.gz</CODE></EM><BR>$ cp ./mysql-proxy-0.5.0/sbin/mysql-proxy /usr/local/sbin<BR><BR>命令语法很简单,它默认使用4040端口.<BR>假设你想代理本机的mysql,直接执行<BR><SPAN class=postbody>$ mysql-proxy &amp;<BR>就可以了.</SPAN><SPAN class=postbody>注意，mysql server必须是5.0或者更高版本.</SPAN><BR><SPAN class=postbody><BR>然后测试一下<BR>$ mysql --host=127.0.0.1 --port=4040 --user=root --password<BR>输入你的root密码,嘿嘿.和使用3306端口的一样.<BR><BR>有人会问:神经病吗?我直接用3306更直接和快速呀,为何多此一举,加个代理?<BR>我能想到的是:<BR>1.在大的应用时,有时需要将读写分离,提高效率,就会需要.<BR></SPAN>2.数据库做负载平衡(<SPAN class=postbody>load balancing)</SPAN>时,也需要.<BR>3.对local用户不需要复杂的安全验证,对远程用户需要ssl时.<BR>4.其它一些特殊要求.<BR></PRE><BR>可惜,我所接触的项目没那么大,暂时不需要负载平衡(<SPAN class=postbody>load balancing)和读写分离,只是个简单意义上的代理.于是我用参数</SPAN>--proxy-backend-addresses 让它代理Data base server这台服务器的3306端口<BR><PRE class=programlisting>$ mysql-proxy --proxy-backend-addresses=192.168.0.1:3306 &amp;<BR><BR>测试连接:<BR>$ mysql --host=localhost --port=4040 --user=root --password<BR>输入Data base server的密码.连接上了.<BR><BR>到网通服务器上测试,<BR>$ mysql --host=双线服务器的网通IP地址 --port=4040 --user=root --password<BR>输入密码后,立即就能看到mysql&gt;了.<BR><BR>套上PHP代码,测试. 速度非常好.目的达到了. <BR><BR>如果你也有类似或者 mysql server 负载平衡、容错 等的应用需求时,不妨也试试<SPAN class=postbody>mysql-proxy,<BR>相信不会让你失望的.<BR>也欢迎和我探讨这方面的问题. 我的联系方式在</SPAN><A href="http://ww.phpv.net/html/contractus.html" target=_blank>这里!!</A><BR>-------------------------------------------------------------------<BR><SPAN style="FONT-FAMILY: verdana,arial,sans-serif">附</SPAN><SPAN class=postbody>mysql-proxy 的所有语法命令:</SPAN><SPAN class=postbody><SPAN style="FONT-SIZE: 18px; LINE-HEIGHT: normal"></SPAN><BR>$ mysql-proxy --help-all<BR><BR>Usage:<BR><BR>mysql-proxy [OPTION...] - MySQL Proxy<BR><BR>Help Options:<BR><BR>-?, --help Show help options<BR>--help-all Show all help options<BR>--help-admin Show options for the admin-module<BR>--help-proxy Show options for the proxy-module<BR><BR>admin module<BR><BR>--admin-address=&lt;host:port&gt;listening address:port of internal admin-server (default: :4041)<BR><BR><BR><BR>proxy-module<BR><BR>--proxy-address=&lt;host:port&gt;listening address:port of the proxy-server (default: :4040)<BR>--proxy-read-only-backend-addresses=&lt;host:port&gt;address:port of the remote slave-server (default: not set)<BR>--proxy-backend-addresses=&lt;host:port&gt;address:port of the remote backend-servers (default: 127.0.0.1:3306)<BR>--proxy-skip-profiling disables profiling of queries (default: enabled)<BR>--proxy-fix-bug-25371 fix bug #25371 (mysqld &gt;5.1.12) for older libmysql versions<BR>--proxy-lua-script=&lt;file&gt;filename of the lua script (default: not set)<BR>--no-proxy Don't start proxy-server<BR><BR><BR><BR>Application Options:<BR>-V, --version Show version<BR>--daemon Start in daemon-mode<BR>--pid-file=&lt;file&gt;PID file in case we are started as daemon<BR><BR></SPAN></PRE><BR> ]]>
</content:encoded>
  </item>
<item>
  <title>Apache服务器使用.htaccess实现图片防盗链教程</title>
  <link>http://phpv.net/html/1582.html</link>
  <comments>http://phpv.net/html/1582.html#comments</comments>
  <pubDate>Thu, 22 Nov 2007 02:05:57 +0800</pubDate>
  <dc:creator>抽烟的蚊子</dc:creator>
<category>
<![CDATA[ 非PHP技术话题 ]]>
</category>
  <guid isPermaLink="false">http://phpv.net/html/1582.html</guid>
  <description><![CDATA[ 所谓盗链，是指其他网站直接链接我们网站上的文件，一般来说，盗链的对象大多为很耗带宽的大体积文件，如图片、视频等。这样造成的后果主要有：增加了服务器的流量负担，影响我们网站的访问速度。

如果你用的是Apache服务器，那么使用.htaccess文件就可以很方便的进行设置，从而防止其他站点的用户盗链我们站点的文件。 ]]></description>
  <content:encoded>
<![CDATA[ 所谓盗链，是指其他网站直接链接我们网站上的文件，一般来说，盗链的对象大多为很耗带宽的大体积文件，如图片、视频等。这样造成的后果主要有：增加了服务器的流量负担，影响我们网站的访问速度。<p>如果你用的是Apache服务器，那么使用.htaccess文件就可以很方便的进行设置，从而防止其他站点的用户盗链我们站点的文件。</p><h3>Apache中的.htaccess文件</h3><p>.htaccess文件是Apache中相当重要的配置文件，其格式为纯文本，它提供了针对目录改变配置的方法，通过在一个特定的文档目录中放置一个包含一个或多个指令的文件，以作用于此目录及其所有子目录。</p><p>通过.htaccess文件，可以实现简单地很多在IIS中很繁琐甚至无法实现的功能，如密码保护、禁止显示目录列表、阻止/允许特定的IP地址、实现网址的301 重定向等等。</p><p>正
如上面所说，.htaccess文件将影响其所在的目录及其子目录，因此，如果我们要保护的内容（此处以防止图片盗链为例，即图片）位于网站内多个目录
下，可以考虑将其放在根目录下；而如果图片有单独的子目录如“/images/”，则只需将其放置在该目录下（当然也可以放到根目录中）。</p><p>需
要注意的是，如果通过FTP方式将创建好的.htaccess上传到服务器上，传输模式应为ASCII而非Binary。上传到服务器后，应将其属性通过
CHMOD修改为644
或“RW-R–R–”，这样，可以保证服务器能够使用同时无法通过浏览器修改，当然，.htaccess的可读属性也存在一定的风险：攻击者可通过它找出
您要保护的对象或认证文件位置——解决办法是将认证文件.htpasswd放到网站根目录之外，这样，便无法通过网络找到它了。</p><h3>使用.htaccess禁止盗链</h3><p>通过.htaccess来防止网站的图片、压缩文件、或视频等非Html文件被盗链的方法相当简单，通过在该文件中加入几句命令即可保护我们宝贵的带宽。例如本站的设置如下：</p><blockquote dir="ltr" style="margin-right: 0px;"><p>RewriteEngine on<br>RewriteCond %{HTTP_REFERER} !^$ [NC]<br>RewriteCond %{HTTP_REFERER} !webeta.cn [NC]<br>RewriteCond %{HTTP_REFERER} !ikuaizi.com [NC]<br>RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]<br>RewriteCond %{HTTP_REFERER} !xianguo.com [NC]<br>RewriteCond %{HTTP_REFERER} !google.com [NC]<br>RewriteCond %{HTTP_REFERER} !bloglines.com [NC]<br>RewriteCond %{HTTP_REFERER} !feedburner.com [NC]<br>RewriteCond %{HTTP_REFERER} !feedsky.com [NC]<br>RewriteRule .*\.(gif|jpg)$ <a href="http://webeta.cn/no.png">http://domain.com/no.png</a> [R,NC,L]</p></blockquote><p>简单的解释一下上述语句：</p><p><strong>1、RewriteCond %{HTTP_REFERER} !^$ [NC]</strong></p><p>允许空“HTTP_REFERER”的访问，即允许用户在浏览器地址栏中直接输入图片地址时图片文件的显示。一般而言，这是可选的，不过，建议这么设置，如果强迫必须具有“HTTP_REFERER”才能访问，可能会带来某些问题，比如说在用户通过代理服务器访问时。</p><p><strong>2、RewriteCond %{HTTP_REFERER} !domain.com [NC