方法ob_start和ob_flush不起作用,为什么? [英] Methods ob_start and ob_flush don't work, why?

查看:357
本文介绍了方法ob_start和ob_flush不起作用,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ob_start()/ob_flush()希望在长时间的导入操作中给我一些进步.

I am using ob_start()/ob_flush() to, hopefully, give me some progress during a long import operation.

这是我在做什么的简单概述:

Here is a simple outline of what I'm doing:

<?php
ob_start ();

echo "Connecting to download Inventory file.<br>";
$conn = ftp_connect($ftp_site) or die("Could not connect");

echo "Logging into site download Inventory file.<br>";
ftp_login($conn,$ftp_username,$ftp_password) or die("Bad login credentials for ". $ftp_site);

echo "Changing directory on download Inventory file.<br>";
ftp_chdir($conn,"INV") or die("could not change directory to INV");

//      connection, local, remote, type, resume
$localname = "INV"."_".date("m")."_".date('d').".csv";
echo "Downloading Inventory file to:".$localname."<br>";

ob_flush();
flush();
sleep(5);

if (ftp_get($conn,$localname,"INV.csv",FTP_ASCII)) 
{
    echo "New Inventory File Downloaded<br>";
    $datapath = $localname;
    ftp_close($conn);
} else {
    ftp_close($conn);
    die("There was a problem downloading the Inventory file.");      
}
ob_flush();
flush();
sleep(5);

$csvfile = fopen($datapath, "r"); // open csv file
$x = 1;
// skip the header line
$line = fgetcsv($csvfile);
$y = (feof($csvfile) ? 2 : 5);
while ((!$debug) ? (!feof($csvfile)) : $x <= $y) {
    $x++;
    $line = fgetcsv($csvfile);
    // do a lot of import stuff here with $line
    ob_flush();
    flush();
    sleep(1);
}

fclose($csvfile); // important: close the file
ob_end_clean();

但是,什么都没有输出到屏幕上.

However, nothing is being output to the screen at all.

我知道数据文件正在下载,因为我看着它所在的目录.

I know the data file is getting downloaded because I watch the directory where it is being placed.

我也知道导入正在发生,这意味着它处于while循环中,因为我可以监视数据库并插入记录.

I also know that the import is happening, meaning that it is in the while loop, because I can monitor the DB and records are being inserted.

关于为什么我没有输出到屏幕的任何想法?

Any ideas as to why I am not getting output to the screen?

推荐答案

您还需要检查PHP设置

You also need to check the PHP settings

某些安装默认为4096,某些默认为关闭

some installs default to 4096, some default to off

output_buffering =关闭
output_buffering = 4096

output_buffering = Off
output_buffering = 4096

同意乔治,但请检查以上设置

agreed with George but do check the above settings

这篇关于方法ob_start和ob_flush不起作用,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆