Home > Backend Development > PHP Tutorial > 数据库操作延时有关问题

数据库操作延时有关问题

WBOY
Release: 2016-06-13 13:32:22
Original
890 people have browsed it

数据库操作延时问题

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
        echo "<script language="JavaScript">alert('数据检测已完成!');</script>";
        echo "<script language="JavaScript">location.href='pmf_rkno_query.php'</script>";
        sleep(10);
        mysql_query("delete from `".$p."` where rkno = '".$rkno."'");    

Copy after login


我的想法是返回对应页面后再进行数据库删除操作。现在代码的效果是等待10秒,删除数据,但是还是停留在当前页。请问哪里出了问题?

------解决方案--------------------
可能是服务器缓存了输出
flush(); // 清除缓存
sleep(10);
------解决方案--------------------
flush(); // 推出缓存
这是必要的,对于ie兼容浏览器还需发送累计256字节以上内容才会被执行,除非程序结束

不过你的这个写法存在风险
一旦
被执行,就相当于用户终止了当前程序的连接,而php默认会终止当前程序的执行,你的
 mysql_query("delete from `".$p."` where rkno = '".$rkno."'"); 
也就没有机会执行了
------解决方案--------------------
加上这些呢???另外不同浏览器是有差异的,,chrome就不一定行得通
ini_set('output_buffering','on');
ini_set('zlib.output_compression', 0);

echo "";
echo str_pad(" ", 1024);
ob_flush();
flush();
sleep(10);
mysql_query("delete from `".$p."` where rkno = '".$rkno."'"); 
……
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template