当我在when服务器上从浏览器执行PHP脚本时,如何才能在它仍在执行时显示脚本结果(代码有许多卷曲,大约需要30分钟才能完全处理)。我有两个服务器,其中一个在调用时会显示每个"echo“,但在另一个服务器上,当脚本完全执行时,它会在30分钟后显示所有内容。这两个服务器都运行在apache上,php 5.6代码:
<?php
error_reporting('E_ALL');
ini_set('error_reporting', 'E_ALL');
set_time_limit ( 2);
$i=0;
$handle = fopen("filmyNasze.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$line = explode("##", $line);
$nazwafilmu = trim($line[0]);
$linkfilmu = trim($line[1]);
$linkfilmu = 'http://xxx.pl' . $linkfilmu;
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $linkfilmu);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: cda.player=html5"));
curl_exec($ch);
$result = curl_exec($ch);
curl_close($ch);
libxml_use_internal_errors(true);
$doc2 = new DOMDocument();
$doc2->loadHTML($result);
$divid = str_replace('/video/', '', trim($line[1]));
foreach( $doc2->getElementsByTagName('div') as $div ) {
if($div->getAttribute('id') == 'mediaplayer' . $divid) {
$array = json_decode($div->getAttribute('player_data'), true);
//echo $array["video"]["file"] . " ## ";
}
}
echo $nazwafilmu . ' ## ' . trim($line[1]) . ' ## ' . $array["video"]["file"] . '<br />';
}
fclose($handle);
}
else {
die('brak pliku .txt');
}
发布于 2016-11-07 19:48:19
您可以使用ob_flush()
和flush()
刷新PHP的输出缓冲区。
http://php.net/manual/en/function.flush.php
<?php
ob_start();
echo 'Something';
ob_flush();
flush();
ob_end_flush();
https://stackoverflow.com/questions/40473291
复制