我正在尝试使输出缓冲正常工作,但页面只是与原始内容保持一致,直到它完成执行......
文件1.php<
<html>
<body>
<form action="importscript.php" method="post" enctype="multipart/form-data">
<p>File: <input type="file" name="import" /></p>
<p><input type="submit" value="Import" /></p>
</form>
</body>
哪些帖子发给...
导入脚本.php<
<?php
ob_start();
set_time_limit(0);
$lines = get contents of file that was submitted - about 50,000 lines on average
echo "Importing - " . count($lines) . " rows<br />"; //I want to show this data
ob_flush();
$sql = <<<SQL
INSERT INTO data (date,time,duration)
VALUES(:date,:time,:duration);
SQL;
$sth = $db->prepare($sql);
$sth->bindParam(':date', $date, PDO::PARAM_STR);
$sth->bindParam(':time', $time, PDO::PARAM_STR);
$sth->bindParam(':duration', $duration, PDO::PARAM_STR);
$execution_time = microtime();
foreach ($lines as $line) {
$lin = str_replace('"','',$line);
$parts = explode(',',$lin);
$parts[0] = str_replace('/', '-', $parts[0]);
$counter++;
$date = $parts[0];
$time = $parts[1];
$duration = $parts[2];
$ex = $sth->execute();
}
$execution_time = microtime() - $execution_time;
$execution_time = sprintf('It took %.5f sec', $execution_time);
echo 'Query Finished. ' . $execution_time' . '<br /><a href="file1.php/">RESET</a>';
ob_flush(); //output this
?>
我已经将脚本缩减了很多,但您可以看到我想在哪里显示一些数据。该脚本平均需要大约 5 分钟,但浏览器只是继续旋转,就好像脚本仍在运行一样。
任何帮助,非常感谢。