Skip to content

Commit

Permalink
bug #19510 [Process] Fix double-fread() when reading unix pipes (nico…
Browse files Browse the repository at this point in the history
…las-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Process] Fix double-fread() when reading unix pipes

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

While looking at the blackfire profile of a `composer install`, I was able to reduce the number of calls to `fread` from 90k to 60k using this patch (and from 60k to <1k with composer/composer#5569 but that's another story).

In fact, we should continue reading only if there might be something next, which won"t be the case if the buffer has not been filled.

Commits
-------

ac17617 [Process] Fix double-fread() when reading unix pipes
  • Loading branch information
nicolas-grekas committed Aug 3, 2016
2 parents 05c9f6c + ac17617 commit 5f59927
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Pipes/UnixPipes.php
Expand Up @@ -120,7 +120,7 @@ public function readAndWrite($blocking, $close = false)
do {
$data = fread($pipe, self::CHUNK_SIZE);
$read[$type] .= $data;
} while (isset($data[0]));
} while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));

if (!isset($read[$type][0])) {
unset($read[$type]);
Expand Down

0 comments on commit 5f59927

Please sign in to comment.