【发布时间】:2015-05-04 12:30:01
【问题描述】:
我不明白我的代码中的问题,我想它与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 行):
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
【问题讨论】: