2
我不明白在我的代码中的问题,我想这是有关flush()
它有时可以工作,有时不会,但如果我重新加载页面,
(然后点击确认表单提交弹出框中的“继续”),它的工作原理!php flush()有时不起作用,重新加载它的页面
这里是我的代码:
Class.php:
private function myFunUpdate($aaa, $bbb, $ccc, $ddd, $eee){
$httpCode = curl_getinfo($aaa, CURLINFO_HTTP_CODE);
if ($httpCode == "200"){
$percent = @round($ccc/$bbb, 2) * 100;
if ($percent > $this->_percentDownloaded){
$this->_percentDownloaded++;
echo '<script>myFunUpdate("'. $percent .'");</script>';
ob_end_flush();
ob_flush();
flush();
}
}
}
的index.php:
<?php
if ($_POST['submit']){
echo '<div><img src="http://example.com/img'.$alpha->stuff1(trim($_POST['myURL'])).'.jpg" /></div>';
echo '<div>'.$alpha->stuff2(trim($_POST['myURL']), 'url').'</div>';
echo '<div id="progressBar">0%</div>';
flush();
if ($alpha->stuff3(trim($_POST['myURL']))){
echo '<div id="divSuccess"></div>';
echo '<script>var progressBar = document.getElementById("progressBar"); progressBar.style.width = progressBar.innerHTML = "0%"; updateProgress("'.trim(strstr($alpha->myFun(), '/'), '/').'");</script>';
flush();
$alpha->stuff4($_POST['param1']);
}else{
echo '<p>Error, something was wrong...</p>';
}
}
?>
而且在PHP的日志文件,我觉得这(指Class.php lines):
PHP Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in xxx.php on line xxx
PHP Notice: ob_flush(): failed to flush buffer. No buffer to flush in xxx.php on line xxx
我必须将它放在Index.php,Class.php或两者的开头? – neoDev
index.php(之前包括class.php) – vivoconunxino
好吧,我会告诉你经过多次尝试,如果它工作正常吗?感谢您的帮助:) – neoDev