php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21895 implicit_flush and flush() not working proplerly with CLI SAPI
Submitted: 2003-01-27 01:12 UTC Modified: 2003-05-01 20:38 UTC
Votes:7
Avg. Score:4.3 ± 0.7
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: haawk at acknet dot org Assigned: helly (profile)
Status: No Feedback Package: Output Control
PHP Version: 4.3.0 OS: FreeBSD 4.7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: haawk at acknet dot org
New email:
PHP Version: OS:

 

 [2003-01-27 01:12 UTC] haawk at acknet dot org
Basically it just seems to not be working at all on my system...however when initiating "php -i" I get:

implicit_flush => On => Off

my configure line was: ./configure --with-mysql --enable-ftp --with-apxs=/usr/local/apache/bin/apxs


Here is the script, which doesn't output ANYTHING until the script ends...it is then all flushed out at once...the warning messages come out as the script executes, but not the echo's or print()'s


<?php
print("weee");
$ftp_server = 'host';
$ftp_user_name = 'user';
$ftp_user_pass = 'pass';
$localprefix = '/usr/home/blah/';
$remoteprefix = '/usr/home/blah/';

$subdirs = array('lib','HELP','ONJOINS','HELP/CHANSERV','HELP/NICKSERV');

foreach ($subdirs as $dir) {
mkdir($localprefix . $dir);
print("mkdir $localprefix . $dir\n");
}

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
        echo "FTP connection has failed!\n";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name\n";
        exit;
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name\n";
    }

// get the files

foreach ($subdirs as $dir) {
ftp_chdir($conn_id, "$remoteprefix$dir");
print("$remoteprefix$dir");
$curdir = ftp_pwd($conn_id);
foreach (ftp_nlist ($conn_id, $curdir) as $file) {
$download = ftp_get($conn_id, $localprefix . $dir . '/' . $file, $file, FTP_ASCII);

// check upload status
if (!$download) {
        echo "FTP upload has failed for $dir/$file!\n";
    } else {
        echo "Downloaded $dir/$file successfully\n";
    }
}
}

// close the FTP stream
ftp_close($conn_id);
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-05 18:21 UTC] sthomas at townnews dot com
I think the key is this:

implicit_flush => On => Off

Is there a double internal pointer to this setting or something?  No amount of setting implicit_flush will
make both of them true.

This script does not output as you'd expect:

<?PHP
ob_implicit_flush(1);

while (TRUE)
{
  echo ".\n";
  sleep(1);
}

?>

This should output a period every second on the CLI, but does not.  Even putting a call to flush() in the while loop does nothing.  I was able to get this to work by using ob_flush() oddly enough.

So essentially, flushing is completely broken unless you use ob_flush.
 [2003-02-06 05:58 UTC] mgf@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That script is working exactly as expected, and the call to ob_flush() is exactly the expected solution.  implicit_flush has no relation to ob_flush(), or output buffers in general.

There are indeed two layers of output buffering, but, slightly confusingly, only one of them is called "output buffering" -- this is the layer handled by the ob_*() functions. If output buffering is on, it works like this:

output goes to (script's) output buffer (ob).

ob_flush() sends it to PHP's "connection" buffer.

flush() (or implicit_flush) sends connection buffer to browser.

If you want to use flush() or implicit_flush to send output to the browser as it's produced, you'd be much better to turn output buffering off.  (You could also take a look at ob_implicit_flush() (http://www.php.net/manual/en/function.ob-implicit-flush.php), but it seems to me this would be rather inefficient.)
 [2003-02-06 06:02 UTC] mgf@php.net
Oops -- my bad -- didn't read enough of the report properly. I see I seem to have explained what you already know.  Sorry!
 [2003-05-01 20:38 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2008-08-14 13:49 UTC] a at a dot com
just set "output_buffering = Off"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC