8

I start my script from command line and it outputs things as they happen but a week ago it stopped outputing and now outputs everything when script finishes. I have ob_start() but as I know this does not affect command line output.

1
  • 2
    Can you please post that core part of the script here? Which version of PHP and on what environment? Commented Dec 11, 2009 at 17:18

2 Answers 2

7

An easy way to do it is to create a function in php like this:

function console_log($message) {
    file_put_contents(STDERR, "\n$message\n\n");
}

where $message is the desired output to command line. Then simply call the function wherever you would like to output and pass in whatever you want it to print.

Sign up to request clarification or add additional context in comments.

Comments

5

You need to remove ob_start()... try this code on the command line, and it will print the text all at once:

<?
ob_start();
echo "test\n";
sleep(10);
echo "buffer\n";
?>

1 Comment

I thought that ob_star() does not function in command line but it really does, this fixed the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.