Skip to content

[Process] Added support for stdout and stderr flush (Issue #7884) #8288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

imobilis
Copy link

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #7884
License MIT
Doc PR symfony/symfony-docs#2728

To-do

  • Submit changes to the documentation.
  • Fix a test broken on travis.
  • Fix mistakes on the documentation.
  • Removed flush + get methods.
  • Changed tests assert calls.

This PR introduces flushing methods for both stdout and stderr on Process class. The new methods are:

  • flushOutput(): clears the output buffer.
  • flushErrorOutput(): clears the error output buffer.

Tests for new methods are included on the PR.

@imobilis
Copy link
Author

I've submitted the doc changes for this PR. Now working on the failed test on travis.

@romainneutron
Copy link
Contributor

Hey,

I like the feature, but I think adding more methods is not a good idea for the api. It results in getOutput, getAndFlushIncrementalOutput, getIncrementalOutput, getAndFlushOutput for the output.

What about adding a boolean $flush parameter like Process::getOutput($flush = false) / Process::getIncrementalOutput($flush = false) and keep the flushOutput method private ?

@imobilis
Copy link
Author

Hi,

I like your suggestion, and I'll modify the PR as soon as I can ;-)

Thank you!

@fabpot
Copy link
Member

fabpot commented Aug 9, 2013

In PHP, arguments as Boolean as hard to understand when using the code: XXX::do(true, false). So, I would rather just keep the flushOutput() and flushErrorOutput() methods and remove the other ones.

@imobilis
Copy link
Author

imobilis commented Aug 9, 2013

I've updated the PR addresing your suggestion, Fabien. Thank you.


$p->run();
$p->flushErrorOutput();
$this->assertEquals('', $p->getErrorOutput());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEmpty() ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right @stloyd assertEmpty is more accurate. I'll change that.

@fabpot fabpot closed this in eb6da72 Sep 27, 2013
*
* @return Process
*/
public function flushOutput()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot shouldn't a flush method send all the buffers content and clear the buffer afterwards, intead of only clearing it? (This is what php does when flushing a buffer, isn't it?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send? We don't send the buffers anyway. It's up to you to get the buffer and do whatever you want with them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me say it in another way. I would not expect that a method called flushxxx() just clears the buffer. If so, this method should be named e.g. CleanBuffer() (to be consitent with php naming)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this context, I don't what it can do on top of removing the data from the buffer. See http://www.catb.org/jargon/html/F/flush.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken from your link

2. [Unix/C] To force buffered I/O to disk, as with an fflush(3) call. This is not an abort or deletion as in sense 1, but a demand for early completion!

Thats what I meant.. It is not delete. Flush is more like a stop now but process everything which is already there.

Since this is not the case here, flush is not the correct term in this situation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the whole thing ;) Actually, I could link to definition 1, which is exactly what we do here, but I won't. I do understand what you mean, except that it does not apply here as the Process class never output/send the buffers, so there are no ambiguities here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that, given functionality of ob_flush(), which sends and cleans the buffer, the methods should be named differently. See #9407.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants