<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OurApache &#187; Hook</title>
	<atom:link href="http://ourapache.com/archives/tag/hook/feed" rel="self" type="application/rss+xml" />
	<link>http://ourapache.com</link>
	<description>我们致力于一个Apache知识的分享网站</description>
	<lastBuildDate>Tue, 13 Apr 2010 05:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Apache2中俩种设置PHP的异同</title>
		<link>http://ourapache.com/archives/318</link>
		<comments>http://ourapache.com/archives/318#comments</comments>
		<pubDate>Tue, 09 Mar 2010 01:38:09 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache高级应用]]></category>
		<category><![CDATA[apache2handler]]></category>
		<category><![CDATA[Hook]]></category>
		<category><![CDATA[配置]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=318</guid>
		<description><![CDATA[Apache2开始引入了Hook方式, 对应的在PHP中也提供了apache2handler这种sapi. 

和我之前介绍过的PHP lifecycle不同, 这种情况下的PHP, 通过注册handler钩子, 从而可以在handler hook阶段有机会处理请求, 通过判断请求的handler, 来确定是否需要处理, 如果需要就会调用自身的处理器.
]]></description>
			<content:encoded><![CDATA[<p>Apache2开始引入了Hook方式, 对应的在PHP中也提供了apache2handler这种sapi.</p>
<p>和我之前介绍过的PHP lifecycle不同, 这种情况下的PHP, 通过注册handler钩子, 从而可以在handler hook阶段有机会处理请求, 通过判断请求的handler, 来确定是否需要处理, 如果需要就会调用自身的处理器.</p>
<p>那么, 这种情况下也就有了多种配置方法, 主要考虑如下俩种方式(第二种可以有多种变种):</p>
<blockquote><p>
第一种: AddType application/x-httpd-php .php<br />
第二种:<br />
      &lt;FilesMatch \.php$&gt;<br />
          SetHandler application/x-httpd-php</p></blockquote>
<p>首先来说, 这俩中方式的起作用的时刻不同, 对于第一种方式来说, 他是在type_check钩子阶段起作用的, 也就是在apache2src/modules/http/mod_mime.c中, 通过注册type_checker钩子, 加入find_ct(content_type), 在find_ct中, 通过配置文件中的mime映射, 或者是通过addType指令增加的映射, 根据文件的扩展来填充请求中的handler字段:</p>
<p>而对于第二种方式, 是在fixup钩子阶段, 通过注册fixups钩子阶段加入core_override_type(apache2src/server/core.c)函数, 来将目录级的配置指令生效.</p>
<p>而fixups钩子是晚于type_checker钩子的, 也是handler钩子之前最后的一个可以利用的钩子. 所以如果同时采用1,2俩种方式, 那么第二种方式会覆盖第一种方式设置的handler.</p>
<p>其次, 俩种方式依赖的数据结构不同, 第一种方式依赖的是一个全局的mime对照表extension_mappings, 这个表由mime配置文件和AddType指令而来.</p>
<p>而对于第二种方式, 它是根据配置文件构造的dir_config而来:</p>
<blockquote><p>
&#8230;.<br />
  core_dir_config *conf =<br />
        (core_dir_config *)ap_get_module_config(r-&gt;per_dir_config,<br />
                                                &amp;core_module);<br />
 <br />
    /* Check for overrides with ForceType / SetHandler<br />
*/<br />
    if (conf-&gt;mime_type &amp;&amp; strcmp(conf-&gt;mime_type, “none”))<br />
        ap_set_content_type(r, (char*) conf-&gt;mime_type);<br />
 <br />
    if (conf-&gt;handler &amp;&amp; strcmp(conf-&gt;handler, “none”))<br />
        r-&gt;handler = conf-&gt;handler;</p></blockquote>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年02月26号 -- <a href="http://ourapache.com/archives/184" title="Apache日志文件（配置和管理）">Apache日志文件（配置和管理）</a></li><li>2009年02月10号 -- <a href="http://ourapache.com/archives/123" title="Apache高级配置中文详解">Apache高级配置中文详解</a></li><li>2009年01月22号 -- <a href="http://ourapache.com/archives/66" title="Apache配置文件(httpd.conf)中文说明">Apache配置文件(httpd.conf)中文说明</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/9" title="apache禁止使用IP访问的实现方法">apache禁止使用IP访问的实现方法</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/7" title="apache中.htaccess的功能及写法">apache中.htaccess的功能及写法</a></li><li>2008年12月27号 -- <a href="http://ourapache.com/archives/3" title="apache的配置优化">apache的配置优化</a></li><li>2008年12月25号 -- <a href="http://ourapache.com/archives/1" title="使用gzip将你的Apache速度提高十倍">使用gzip将你的Apache速度提高十倍</a></li></ul>
	标签：<a href="http://ourapache.com/archives/tag/apache2handler" title="apache2handler" rel="tag">apache2handler</a>, <a href="http://ourapache.com/archives/category/advanced" title="Apache高级应用" rel="tag">Apache高级应用</a>, <a href="http://ourapache.com/archives/tag/hook" title="Hook" rel="tag">Hook</a>, <a href="http://ourapache.com/archives/tag/%e9%85%8d%e7%bd%ae" title="配置" rel="tag">配置</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/318/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

