﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-flyonok-随笔分类-php</title><link>http://www.cppblog.com/flyonok/category/13189.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 07 Mar 2012 11:41:44 GMT</lastBuildDate><pubDate>Wed, 07 Mar 2012 11:41:44 GMT</pubDate><ttl>60</ttl><item><title>在centos上安装mysql5.5+nginx1.0.13+php5.3.8</title><link>http://www.cppblog.com/flyonok/archive/2012/03/07/167306.html</link><dc:creator>flyonok</dc:creator><author>flyonok</author><pubDate>Wed, 07 Mar 2012 04:23:00 GMT</pubDate><guid>http://www.cppblog.com/flyonok/archive/2012/03/07/167306.html</guid><wfw:comment>http://www.cppblog.com/flyonok/comments/167306.html</wfw:comment><comments>http://www.cppblog.com/flyonok/archive/2012/03/07/167306.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyonok/comments/commentRss/167306.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyonok/services/trackbacks/167306.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: mysql nginx php 在centos上的源码安装&nbsp;&nbsp;<a href='http://www.cppblog.com/flyonok/archive/2012/03/07/167306.html'>阅读全文</a><img src ="http://www.cppblog.com/flyonok/aggbug/167306.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyonok/" target="_blank">flyonok</a> 2012-03-07 12:23 <a href="http://www.cppblog.com/flyonok/archive/2012/03/07/167306.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>php 运行的两种方式</title><link>http://www.cppblog.com/flyonok/archive/2010/08/15/123507.html</link><dc:creator>flyonok</dc:creator><author>flyonok</author><pubDate>Sun, 15 Aug 2010 08:37:00 GMT</pubDate><guid>http://www.cppblog.com/flyonok/archive/2010/08/15/123507.html</guid><wfw:comment>http://www.cppblog.com/flyonok/comments/123507.html</wfw:comment><comments>http://www.cppblog.com/flyonok/archive/2010/08/15/123507.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyonok/comments/commentRss/123507.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyonok/services/trackbacks/123507.html</trackback:ping><description><![CDATA[<meta http-equiv="content-type" content="text/html; charset=utf-8"><span  style="font-family: Verdana, 'Lucida Grande', Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px; "><div class="articletit"><h1 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; font-size: 16px; padding-bottom: 5px; ">PHP在Apache中两种工作方式的区别(CGI模式、Apache 模块DLL)</h1></div><div class="articletime">发布时间:2008-12-17 10:06 　　作者: 网络转载 　　信息来源: www.cn-web.com　　<span class="mydiscuss">[<a href="http://www.phpchina.com/html/30/n-34030.html#postcomm" style="color: rgb(29, 88, 209); text-decoration: none; ">我来说两句</a>(<strong>323</strong>条)]</span></div><div id="articlecont"><div id="articlebody"><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><a href="http://www.cnblogs.com/ljkeke/admin/javascript:;" target="_self" style="color: rgb(29, 88, 209); text-decoration: none; "><u><strong>Windows</strong></u></a>&nbsp;下有两种<a href="http://www.cnblogs.com/ljkeke/admin/javascript:;" target="_self" style="color: rgb(29, 88, 209); text-decoration: none; "><u><strong>方法</strong></u></a>使&nbsp;<a href="http://www.cnblogs.com/ljkeke/admin/javascript:;" target="_self" style="color: rgb(29, 88, 209); text-decoration: none; "><u><strong>PHP</strong></u></a>&nbsp;<a href="http://www.cnblogs.com/ljkeke/admin/javascript:;" target="_self" style="color: rgb(29, 88, 209); text-decoration: none; "><u><strong>工作</strong></u></a>于&nbsp;<a href="http://www.cnblogs.com/ljkeke/admin/javascript:;" target="_self" style="color: rgb(29, 88, 209); text-decoration: none; "><u><strong>Apache</strong></u></a>&nbsp;2.0.x 之中。一种是 使用&nbsp;<a href="http://www.cnblogs.com/ljkeke/admin/javascript:;" target="_self" style="color: rgb(29, 88, 209); text-decoration: none; "><u><strong>CGI</strong></u></a>&nbsp;可执行程序，另一种是适用 Apache 模块的&nbsp;<a href="http://www.cnblogs.com/ljkeke/admin/javascript:;" target="_self" style="color: rgb(29, 88, 209); text-decoration: none; "><u><strong>DLL</strong></u></a>。<br><span style="font-weight: bold; ">这两种工作方式的<a href="http://www.cnblogs.com/ljkeke/admin/javascript:;" target="_self" style="color: rgb(29, 88, 209); text-decoration: none; "><u><strong>安装</strong></u></a>：</span><br>&nbsp;<br>&nbsp;<span style="text-decoration: underline; ">PHP 在 Apache 2.0 中的 CGI 方式<br></span>ScriptAlias /php/ "c:/php/"<br>AddType application/x-httpd-php .php</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "># 对 PHP 4 用这行<br>Action application/x-httpd-php "/php/php.exe"</p><div># 对 PHP 5 用这行<br>Action application/x-httpd-php "/php/php-cgi.exe"<br><span style="text-decoration: underline; ">&nbsp;PHP 在 Apache 2.0 中的模块方式</span></div><div># 对 PHP 4 用这两行：<br>LoadModule php4_module "c:/php/php4apache2.dll"<br># 别忘了从 sapi 目录中把 php4apache2.dll 拷贝出来！<br>AddType application/x-httpd-php .php</div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "># 对 PHP 5 用这两行：<br>LoadModule php5_module "c:/php/php5apache2.dll"<br>AddType application/x-httpd-php .php</p><div># 配置 php.ini 的路径<br>PHPIniDir "C:/php"</div><div><br><span style="font-weight: bold; ">这两种工作方式的区别：</span></div><div>在CGI模式下，如果客户机请求一个php文件，Web服务器就调用php.exe去解释这个文件，然后再把解释的结果以网页的形式返回给客户机；</div><div>而在模块化(DLL)中，PHP是与Web服务器一起启动并运行的。</div><div>所以从某种角度上来说，以apache模块方式安装的 PHP4有着比CGI模式更好的安全性以及更好的执行效率和速度</div></div></div></span>
<img src ="http://www.cppblog.com/flyonok/aggbug/123507.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyonok/" target="_blank">flyonok</a> 2010-08-15 16:37 <a href="http://www.cppblog.com/flyonok/archive/2010/08/15/123507.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP develope notes</title><link>http://www.cppblog.com/flyonok/archive/2010/03/12/109508.html</link><dc:creator>flyonok</dc:creator><author>flyonok</author><pubDate>Fri, 12 Mar 2010 04:09:00 GMT</pubDate><guid>http://www.cppblog.com/flyonok/archive/2010/03/12/109508.html</guid><wfw:comment>http://www.cppblog.com/flyonok/comments/109508.html</wfw:comment><comments>http://www.cppblog.com/flyonok/archive/2010/03/12/109508.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyonok/comments/commentRss/109508.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyonok/services/trackbacks/109508.html</trackback:ping><description><![CDATA[1、防止 cross-site attack:<br>&nbsp; 对browser提交过来的数据用以下函数过滤<br>&nbsp; <tt>strip_tags和</tt><tt>htmlentities，请注意两个函数的不同<br>2、</tt>防止SQL injection attack：<br>&nbsp; use placeholder，比如用如下语句，$db-&gt;query('INSERT INTO dishes (dish_name) VALUES (?)',
array($_POST['new_dish_name']));就可以防止sql攻击了。<br><br><img src ="http://www.cppblog.com/flyonok/aggbug/109508.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyonok/" target="_blank">flyonok</a> 2010-03-12 12:09 <a href="http://www.cppblog.com/flyonok/archive/2010/03/12/109508.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP SPL，遗落的宝石</title><link>http://www.cppblog.com/flyonok/archive/2010/03/12/109507.html</link><dc:creator>flyonok</dc:creator><author>flyonok</author><pubDate>Fri, 12 Mar 2010 03:50:00 GMT</pubDate><guid>http://www.cppblog.com/flyonok/archive/2010/03/12/109507.html</guid><wfw:comment>http://www.cppblog.com/flyonok/comments/109507.html</wfw:comment><comments>http://www.cppblog.com/flyonok/archive/2010/03/12/109507.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyonok/comments/commentRss/109507.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyonok/services/trackbacks/109507.html</trackback:ping><description><![CDATA[<p><a  href="http://cn.php.net/spl" title="http://cn.php.net/spl">SPL，PHP
标准库（Standard PHP Library）</a>，此从 PHP 5.0 起内置的组件和接口，并且从 PHP5.3
已逐渐的成熟。SPL 其实在所有的 PHP5 开发环境中被内置，同时无需任何设置。</p>
<p>似乎众多的 PHP 开发人员基本没有使用它，甚至闻所未闻。究其原因，可以追述到它那阳春白雪般的说明文档，使你忽略了&#8220;它的存在&#8221;。</p>
<p>SPL 这块宝石犹如铁达尼的&#8220;海洋之心&#8221;般，被沉入海底。而现在它应该被我们捞起，并将它穿戴在应有的位置 ，而这也是这篇文章所要表述的观点。</p>
<p>那么，SPL 提供了什么？</p>
<p>SPL 对 PHP 引擎进行了扩展，例如 ArrayAccess、Countable 和 SeekableIterator
等接口，它们用于以数组形式操作对象。同时，你还可以使用 RecursiveIterator、ArrayObejcts
等其他迭代器进行数据的迭代操作。</p>
<p>它还内置几个的对象例如 Exceptions、SplObserver、Spltorage 以及
spl_autoload_register、spl_classes、iterator_apply 等的帮助函数（helper
functions），用于重载对应的功能。</p>
<p>这些工具聚合在一起就好比是把多功能的瑞士军刀，善用它们可以从质上提升 PHP 的代码效率。那么，我们如何发挥它的威力？</p>
<h4>重载 autoloader</h4>
<p>如果你是位&#8220;教科书式的程序员&#8221;，那么你保证了解如何使用 __autoload 去代替 includes/requires
操作惰性载入对应的类，对不？</p>
<p>但久之，你会发现你已经陷入了困境，首先是你要保证你的类文件必须在指定的文件路径中，例如在 Zend
框架中你必须使用&#8220;_&#8221;来分割类、方法名称（你如何解决这一问题？）。</p>
<p>另外的一个问题，就是当项目变得越来越复杂， __autoload
内的逻辑也会变得相应的复杂。到最后，甚至你会加入异常判断，以及将所有的载入类的逻辑如数写到其中。</p>
<p>大家都知道&#8220;鸡蛋不能放到一个篮子中&#8221;，利用 SPL 可以分离 __autoload 的载入逻辑。只需要写个你自己的 autoload
函数，然后利用 SPL 提供的函数重载它。</p>
<p>例如上述 Zend 框架的问题，你可以重载 Zend loader 对应的方法，如果它没有找到对应的类，那么就使用你先前定义的函数。</p>
<pre>&lt;?php<br>class MyLoader {<br>    public static function doAutoload($class) {<br>        // 本模块对应的 autoload 操作<br>    }<br>}<br><br>spl_autoload_register( array('MyLoader', 'doAutoload') );</pre>
<p>正如你所见，<a  href="http://cn2.php.net/manual/en/function.spl-autoload-register.php" title="http://cn2.php.net/manual/en/function.spl-autoload-register.php">spl_autoload_register</a>
还能以数组的形式加入多个载入逻辑。同时，你还可以利用 <a  href="http://cn2.php.net/manual/en/function.spl-autoload-unregister.php" title="http://cn2.php.net/manual/en/function.spl-autoload-unregister.php">spl_autoload_unregister</a>
移除已经不再需要的载入逻辑，这功能总会用到的。</p>
<h4>迭代器</h4>
<p>迭代是常见设计模式之一，普遍应用于一组数据中的统一的遍历操作。可以毫不夸张的说，SPL 提供了所有你需要的对应数据类型的迭代器。</p>
<p>有个非常好的案例就是遍历目录。常规的做法就是使用 scandir ，然后跳过&#8220;.&#8220; 和
&#8220;..&#8221;，以及其它未满足条件的文件。例如你需要遍历个某个目录抽取其中的图片文件，就需要判断是否是 jpg、gif 结尾。</p>
<p>下面的代码就是使用 SPL 的迭代器执行上述递归寻找指定目录中的图片文件的例子：</p>
<pre>&lt;?php<br>class RecursiveFileFilterIterator extends FilterIterator {<br>    // 满足条件的扩展名<br>    protected $ext = array('jpg','gif');<br><br>    /**<br>     * 提供 $path 并生成对应的目录迭代器<br>     */<br>    public function __construct($path) {<br>        parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));<br>    }<br><br>    /**<br>     * 检查文件扩展名是否满足条件<br>     */<br>    public function accept() {<br>        $item = $this-&gt;getInnerIterator();<br>        if ($item-&gt;isFile() &amp;&amp; <br>                in_array(pathinfo($item-&gt;getFilename(), PATHINFO_EXTENSION), $this-&gt;ext)) {<br>            return TRUE;<br>        }<br>    }<br>}<br><br>// 实例化<br>foreach (new RecursiveFileFilterIterator('/path/to/something') as $item) {<br>    echo $item . PHP_EOL;<br>}</pre>
<p>你可能会说，这不是花了更多的代码去办同一件事情吗？那么，查看上面的代码，你不是拥有了具有高度重用而且可以测试的代码了吗 :^)</p>
<p>下面是 SPL 提供的其他的迭代器：</p>
<ul>
    <li>RecursiveIterator </li>
    <li>RecursiveIteratorIterator </li>
    <li>OuterIterator </li>
    <li>IteratorIterator </li>
    <li>FilterIterator </li>
    <li>RecursiveFilterIterator </li>
    <li>ParentIterator </li>
    <li>SeekableIterator </li>
    <li>LimitIterator </li>
    <li>GlobIterator </li>
    <li>CachingIterator </li>
    <li>RecursiveCachingIterator </li>
    <li>NoRewindIterator </li>
    <li>AppendIterator </li>
    <li>RecursiveIteratorIterator </li>
    <li>InfiniteIterator </li>
    <li>RegexIterator </li>
    <li>RecursiveRegexIterator </li>
    <li>EmptyIterator </li>
    <li>RecursiveTreeIterator </li>
    <li>ArrayIterator </li>
</ul>
<p>自 PHP5.3 开始，会内置其他更多的迭代器，我想你都可以尝试下，或许它能改变你编写传统代码的习惯。</p>
<h4>SplFixedArray</h4>
<p>SPL 还内置了一系列的数组操作工具，例如可以使用 <a  href="http://cn2.php.net/manual/en/class.splfixedarray.php" title="http://cn2.php.net/manual/en/class.splfixedarray.php">SplFixedArray</a>
实例化一个固定长度的数组。那么为什么要使用它？因为它更快，甚至它关系着你的工资问题 :^)</p>
<p>我们知道 PHP 常规的数组包含不同类型的键，例如数字、字符串等，并且长度是可变的。正是因为这些&#8220;高级功能&#8221;，PHP
以散列（hash）的方式通过键得到对应的值 -- 其实这在特定情况这会造成性能问题。</p>
<p>而 SplFixedArray 因为是使用固定的数字键，所以它并没有使用散列存储方式。不确切的说，甚至你可以认为它就是个 C
数组。这就是为什么 SplFixedArray 会比通常数组要快的原因（仅在 PHP5.3 中）。</p>
<p>那到底有多快呢，下面的组数据可以让你窥其究竟。</p>
<p><a  href="http://developer.studivz.net/2009/03/18/php-spl-data-structures-benchmark/" title="http://developer.studivz.net/2009/03/18/php-spl-data-structures-benchmark/">更
详细的评测可以参考这里</a>，如果你需要大量的数组操作，那么你可以尝试下，相信它是值得信赖的。</p>
<h4>数据结构</h4>
<p><a  href="http://cn2.php.net/manual/en/spl.datastructures.php" title="http://cn2.php.net/manual/en/spl.datastructures.php">同时 SPL
还提供了些数据结构基本类型的实现</a>。虽然我们可以使用传统的变量类型来描述数据结构，例如用数组来描述堆栈（Strack）--
然后使用对应的方式 pop 和
push（array_pop()、array_push()），但你得时刻小心，&#183;因为毕竟它们不是专门用于描述数据结构的 --
一次误操作就有可能破坏该堆栈。</p>
<p>而 <a  href="http://cn2.php.net/manual/en/class.splstack.php" title="http://cn2.php.net/manual/en/class.splstack.php">SPL 的 SplStack</a>
对象则严格以堆栈的形式描述数据，并提供对应的方法。同时，这样的代码应该也能理解它在操作堆栈而非某个数组，从而能让你的同伴更好的理解相应的代码，并
且它更快。</p>
<p>最后，可能上述那些惨白的例子还不足矣&#8220;诱惑你&#8221;去使用 SPL。实践出真知，SPL
更多、更强大的功能需要你自己去挖掘。而它正如宝石般的慢慢雕砌，才能散发光辉。</p>
<p>PS，有关 SPL 详细的中文文档，阮一峰同学这里有份更详细的笔记《<a  href="http://www.kuqin.com/web/20090614/56678.html" target="_blank">PHP SPL笔记</a>》，推荐。</p><img src ="http://www.cppblog.com/flyonok/aggbug/109507.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyonok/" target="_blank">flyonok</a> 2010-03-12 11:50 <a href="http://www.cppblog.com/flyonok/archive/2010/03/12/109507.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>