English 中文(简体)
防止在吉大港山区采取应对措施
原标题:Prevent local caching of responses in HTTP streaming

我正试图将数据从档案中读到耳光客户。 我能够成功地将数据流出,但我的答复却正在 ca,我希望防止这种情况发生。 之所以出现这种情况,是因为我的平坦档案中的数据条目相互独立,而且我也希望予以处理。 例如,我的档案包括:

{idle_time:94125387364,system_time:98954710321,user_time:3683963615} {idle_time:94125387789,system_time:98954710456,user_time:3683963845} {idle_time:94125387876,system_time:98954710678,user_time:3683963986}

so instead of getting {idle_time:94125387876,system_time:98954710678,user_time:3683963986} (THIRD ENTRY) as xmlhttprequest.responsetext, I receive

{idle_time:94125387364,system_time:98954710321,user_time:3683963615} <br/>
{idle_time:94125387789,system_time:98954710456,user_time:3683963845} <br/>
{idle_time:94125387876,system_time:98954710678,user_time:3683963986}

注: 我对断线标和空白处不抱担忧。

My PHP script looks like this, test.php

<?php
set_time_limit(0); 
$filename =  D:Smoke_Testdata.txt ;

function flush2 (){
echo(str_repeat(   ,256));
// check that buffer is actually set before flushing
if (ob_get_length()){            
    @ob_flush();
    @flush();
    @ob_end_flush();
}    
@ob_start();
}

$file_last_modified_time = 0;

while(true) 
{
$modified_time = filemtime($filename);
$processor_info = "";
if ($file_last_modified_time < $modified_time)  
{
    header("Expires: Sun, 20 Jan 1985 00:00:00 GMT"); // date in the past
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
    $file_last_modified_time = $modified_time;
    $handle = fopen($filename,"r");
    $processor_info = fgets ($handle);
    fclose ($handle);
    @ob_clean();
    echo $processor_info."<br/>";
    //flush2();
}
flush2();
sleep(1);
clearstatcache(true, $filename);
}

?>

and my html page looks like this: Home.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-     transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script type="text/javascript" language = "javascript">
function read_file ()
{
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
        if (xmlhttp.readyState==4 || xmlhttp.readyState==3 ) //&& xmlhttp.status==200)
        {
            handle_data (xmlhttp.responseText);
        }
      }
    xmlhttp.open("POST","test.php",true);
    xmlhttp.send();
}

function handle_data (input)
{
    document.getElementById("txtResponse").innerHTML=input;
}
</script>

</head>
<body>
<p>
<input type="button" id="dtnSendRequest" value="Send Request" onclick="read_file()"/>
</p>
<p>
response : <span id="txtResponse"></span>
<!-- <input type="text" id="txtResponse" width="500"/> -->
</p>
</body>
</html>
最佳回答
问题回答

试图将这一内容添加到你的实验室档案中。

header("Expires: Sun, 20 Jan 1985 00:00:00 GMT"); // date in the past
header("Cache-Control: no-cache");
header("Pragma: no-cache"); 

• 利用这一手段强迫不切身:

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

在发送任何产出之前,确保你这样做。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签