我的页面里里有好几个ajax请求 还有flex 名字是index.html
问题是当我从这个页面跳到别的页面时会很慢。我怀疑是目标文件的原因,于是我就写了个目标测试文件test.php只是输出
hello world结果还是慢。接着我又把我index.html里调用ajax暗请求的js函数关掉结果快多了。后来测试我基本得出 我的跳转请求排在了ajax请求后面了,它好像是先执行完ajax请求再去跳转。槽糕的是我index.html的ajax请求是十秒钟一次。
我不知道怎么修改我的代码(是我的ajax请求调用时机不对,还是怎么了?) 让它快起来。 请高人出招.以下是我的代码:index.html
function createXmlRequestObject()
{
if( window.XMLHttpRequest )
{
xmlRequestObject = new XMLHttpRequest();
}
else if( window.ActiveXObject )
{
try
{
xmlRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlRequestObject;
}function startAjax(xRO, url, method, callback, postData)
{
if( xRO )
{
xRO.onreadystatechange = callback;
xRO.open(""+method, url, true);
xRO.setRequestHeader("Content-Type", "application/x-www-form-urlencoded" );
xRO.send( postData );
}
}function fnTraceInfo()
{
var xro_trace = createXmlRequestObject();
startAjax(xro_trace, '../monitor.php?action=trace', 'GET', function(){fnTraceInfoCb(xro_trace)}, null);
}
//回调函数
function fnTraceInfoCb(xro_trace)
{
if (xro_trace.readyState == 4)
{
if (xro_trace.status == 200 )
{
var xroText2 = xro_trace.responseText;
document.getElementById('devices').innerHTML = xroText2;
uf = setTimeout(fnTraceInfo()', 10000);
}
}
}
fnTraceInfo();
问题是当我从这个页面跳到别的页面时会很慢。我怀疑是目标文件的原因,于是我就写了个目标测试文件test.php只是输出
hello world结果还是慢。接着我又把我index.html里调用ajax暗请求的js函数关掉结果快多了。后来测试我基本得出 我的跳转请求排在了ajax请求后面了,它好像是先执行完ajax请求再去跳转。槽糕的是我index.html的ajax请求是十秒钟一次。
我不知道怎么修改我的代码(是我的ajax请求调用时机不对,还是怎么了?) 让它快起来。 请高人出招.以下是我的代码:index.html
function createXmlRequestObject()
{
if( window.XMLHttpRequest )
{
xmlRequestObject = new XMLHttpRequest();
}
else if( window.ActiveXObject )
{
try
{
xmlRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlRequestObject;
}function startAjax(xRO, url, method, callback, postData)
{
if( xRO )
{
xRO.onreadystatechange = callback;
xRO.open(""+method, url, true);
xRO.setRequestHeader("Content-Type", "application/x-www-form-urlencoded" );
xRO.send( postData );
}
}function fnTraceInfo()
{
var xro_trace = createXmlRequestObject();
startAjax(xro_trace, '../monitor.php?action=trace', 'GET', function(){fnTraceInfoCb(xro_trace)}, null);
}
//回调函数
function fnTraceInfoCb(xro_trace)
{
if (xro_trace.readyState == 4)
{
if (xro_trace.status == 200 )
{
var xroText2 = xro_trace.responseText;
document.getElementById('devices').innerHTML = xroText2;
uf = setTimeout(fnTraceInfo()', 10000);
}
}
}
fnTraceInfo();
解决方案 »
- 如何获取服务器上的某个XML文件的访问统计记录
- frameset 显示空白是怎么回事啊
- php如何链接ms sqlserver
- 请问在PHP中 @ 到底是什么意思 如:$register_globals = @ini_get('register_globals');
- 准备做一个新闻小偷,大家有什么建议或者现成代码?
- 怎么用smarttemplate将从数据库中查询的数据显示在一个表格?
- 大家看看我汉化改编的xmb论坛,主页上提供下载,以及hack程序
- PHP的文件上传问题:可不可以在一个表单里既有文件还有别的表单(如Text)?怎末处理?
- IIS+PHP 只能访问首页,其它页面全是404错误,求有经验的人帮忙!!
- 错误信息显示
- 各位老师,帮我看看能不能改成支持可分页。
- 紧急求救,页面显示不正常
最近在开发一个项目,其中有1个PHP页面需要执行较长时间,而且我发现,在执行这个页面的时候,其他的页面都不能访问了,需要等这个页面执行完成以后,其他页面才能打开。 猜想了一下,有以下几种可能 1. Web Server(Apache 2.2)是不是只能同时处理1个客户端连接?
2. 是不是打开MySQL数据库的时候被阻塞了?
3. 是不是session_start导致了阻塞?
于是,我写了几个页面测试了一下,发现是session导致了阻塞,而其他两种情况不会造成阻塞。 查了下PHP的Bug列表,发现有人提出了这个问题:
Description:
------------
Calling session_start() appears to wait until other scripts have exitedthat are using the same session. My guess is the 1st request locks the
session file for exclusive use, and the second request blocks until it
can open it.
PHP官方的回复是:
Thank you for taking the time to write to us, but this is not a bug.This is expected, the session file is locked to avoid corruption. 结合了PHP的Session机制,找到了阻塞的原因。由于PHP的Session信息是写入文件的,1个客户端占有1个session文件。因此,当 session_start被调用的时候,该文件是被锁住的,而且是以读写模式锁住的(因为程序中可能要修改session的值),这样,第2次调用 session_start的时候就被阻塞了。 最简解决方法: 查了PHP的手册,发现一个session_write_close函数,作用是Write session data and end session,也就是写session的数据,同时关闭这个session。因此,我们可以在用完session之后,调用这个函数关闭session 文件即可接触锁定。一般,session是用来记录用户身份信息的,以便PHP进行身份认证,因此完全可以将session的读写放在页面刚开始执行的时候,在执行完以后,马上调用session_write_close函数即可。