使用PHP 5.3.5/IIS7添加到301标头的默认内容

问题描述:

http://www.hesa.ac.uk上,我们使用自定义404处理脚本将用户从例如http://www.hesa.ac.uk/press重定向到实际的URL,这是一个丑陋的CMS:http://www.hesa.ac.uk/index.php?option=com_content&task=category&sectionid=1&id=1&Itemid=161使用PHP 5.3.5/IIS7添加到301标头的默认内容

我们正在运行fast-cgi。

301头被发送,然后是位置头。

对于99%的用户来说,它工作正常,但其中一些用户报告5到6秒的加载时间。这一点,我们认为,由于有点流浪含量在重定向出现:

<head><title>Document Moved</title></head> 
<body><h1>Object Moved</h1>This document may be found <a HREF="http://www.hesa.ac.uk/index.php?option=com_content&amp;task=category&amp;sectionid=1&amp;id=1&amp;Itemid=161">here</a></body> 

这不是我们可以看到代码的任何输出。下面是其中实际执行重定向的方法:

/** 
* Do the actual redirection to the win URL 
* 
*/ 
function doRedirection() { 


     //start output buffering to trap any content that is output by default by the headers 
     @ob_start(); 

     //permanently moved header 
     //header('HTTP/1.1 301 Moved Permanently'); 

     //fast-cgi, so use this:   
     header('Status: 301 Moved Permanently', true);    

     @ob_end_clean(); // clear output buffer 

     //location header 
     header("Location: ". $this->winUrl); 

     @ob_end_clean(); // clear output buffer 

     die(); 



} 

我似乎无法找到这表明如何停止的内容被输出的这种额外位的任何资源。我已经尝试了上述方法的各种变体来进行重定向。

有没有人有类似的问题?有没有人有任何想法?

干杯,

编辑:我们已经意识到,这是预期的行为IIS7,但IIS6永远不会使用相同的代码来做到这一点,而且无论是期待与否,我们的用户抱怨,这似乎是问题。编辑2:似乎唯一可行的解​​决方案是放弃这种方法,而是转向IIS7的URL重写功能,这需要编写一个C#类,它克隆了PHP类的功能,然后将其插入到IIS中。编辑3:但是,设置内容长度:0头可能可能有所帮助。虽然没有测试过。

原来问题实际上是在重定向代码中使用内置的PHP函数getHostByAddr()。没有正确设置其DNS记录的客户端主机会遇到5到6秒的延迟(从IIS7开始,我们从来没有遇到IIS6的这个问题)的getHostByAddr()延迟。如果找到替代功能并将其交换出去,问题就会消失。