Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Stream
File: ProcessOutput.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Stream_ProcessOutput extends MWP_Stream_Callable
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* @var Symfony_Process_Process
[14] Fix | Delete
*/
[15] Fix | Delete
private $process;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @var bool
[19] Fix | Delete
*/
[20] Fix | Delete
private $ran = false;
[21] Fix | Delete
[22] Fix | Delete
public function __construct(Symfony_Process_Process $process)
[23] Fix | Delete
{
[24] Fix | Delete
parent::__construct(array($this, 'getIncrementalOutput'));
[25] Fix | Delete
$this->process = $process;
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Returns incremental process output (even if empty string) or false if the process has finished
[30] Fix | Delete
* successfully and all output was already returned.
[31] Fix | Delete
*
[32] Fix | Delete
* @throws Symfony_Process_Exception_ProcessFailedException If the process did not exit successfully.
[33] Fix | Delete
*
[34] Fix | Delete
* @internal
[35] Fix | Delete
*
[36] Fix | Delete
* @return string|false
[37] Fix | Delete
*/
[38] Fix | Delete
public function getIncrementalOutput()
[39] Fix | Delete
{
[40] Fix | Delete
if (!$this->ran) {
[41] Fix | Delete
$this->ran = true;
[42] Fix | Delete
try {
[43] Fix | Delete
$this->process->start();
[44] Fix | Delete
} catch (Symfony_Process_Exception_ExceptionInterface $e) {
[45] Fix | Delete
throw new Symfony_Process_Exception_ProcessFailedException($this->process);
[46] Fix | Delete
}
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
if ($this->process->isRunning()) {
[50] Fix | Delete
$output = $this->process->getIncrementalOutput();
[51] Fix | Delete
$this->process->clearOutput();
[52] Fix | Delete
[53] Fix | Delete
if (strlen($output) < Symfony_Process_Pipes_PipesInterface::CHUNK_SIZE) {
[54] Fix | Delete
// Don't hog the processor while waiting for incremental process output.
[55] Fix | Delete
usleep(100000);
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
// The stream will be read again because we're returning a string.
[59] Fix | Delete
return (string)$output;
[60] Fix | Delete
} else {
[61] Fix | Delete
if (!$this->process->isSuccessful()) {
[62] Fix | Delete
throw new Symfony_Process_Exception_ProcessFailedException($this->process);
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
$output = $this->process->getIncrementalOutput();
[66] Fix | Delete
$this->process->clearOutput();
[67] Fix | Delete
[68] Fix | Delete
// The process has finished and is successful. This part will probably get run twice,
[69] Fix | Delete
// first time we'll return final output, second time we'll return 'false' and break the loop.
[70] Fix | Delete
return strlen($output) ? $output : false;
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function