Skip to content
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

Improve performance by prefixing all global functions calls with \ to skip the look up and resolve process and go straight to the global function #68

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Process extends EventEmitter
*/
public function __construct($cmd, $cwd = null, array $env = null, array $fds = null)
{
if (!function_exists('proc_open')) {
if (!\function_exists('proc_open')) {
throw new \LogicException('The Process class relies on proc_open(), which is not available on your PHP installation.');
}

Expand All @@ -97,7 +97,7 @@ public function __construct($cmd, $cwd = null, array $env = null, array $fds = n
);
}

if (DIRECTORY_SEPARATOR === '\\') {
if (\DIRECTORY_SEPARATOR === '\\') {
foreach ($fds as $fd) {
if (isset($fd[0]) && $fd[0] === 'pipe') {
throw new \LogicException('Process pipes are not supported on Windows due to their blocking nature on Windows');
Expand Down Expand Up @@ -142,20 +142,20 @@ public function start(LoopInterface $loop, $interval = 0.1)
$sigchild = 3;
}

$cmd = sprintf('(%s) ' . $sigchild . '>/dev/null; code=$?; echo $code >&' . $sigchild . '; exit $code', $cmd);
$cmd = \sprintf('(%s) ' . $sigchild . '>/dev/null; code=$?; echo $code >&' . $sigchild . '; exit $code', $cmd);
}

// on Windows, we do not launch the given command line in a shell (cmd.exe) by default and omit any error dialogs
// the cmd.exe shell can explicitly be given as part of the command as detailed in both documentation and tests
$options = array();
if (DIRECTORY_SEPARATOR === '\\') {
if (\DIRECTORY_SEPARATOR === '\\') {
$options['bypass_shell'] = true;
$options['suppress_errors'] = true;
}

$this->process = proc_open($cmd, $fdSpec, $pipes, $this->cwd, $this->env, $options);
$this->process = \proc_open($cmd, $fdSpec, $pipes, $this->cwd, $this->env, $options);

if (!is_resource($this->process)) {
if (!\is_resource($this->process)) {
throw new \RuntimeException('Unable to launch a new process.');
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public function close()
$this->closeExitCodePipe();
}

$exitCode = proc_close($this->process);
$exitCode = \proc_close($this->process);
$this->process = null;

if ($this->exitCode === null && $exitCode !== -1) {
Expand Down Expand Up @@ -263,10 +263,10 @@ public function terminate($signal = null)
}

if ($signal !== null) {
return proc_terminate($this->process, $signal);
return \proc_terminate($this->process, $signal);
}

return proc_terminate($this->process);
return \proc_terminate($this->process);
}

/**
Expand Down Expand Up @@ -385,10 +385,10 @@ public final static function isSigchildEnabled()
return self::$sigchild;
}

ob_start();
phpinfo(INFO_GENERAL);
\ob_start();
\phpinfo(INFO_GENERAL);

return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
return self::$sigchild = false !== \strpos(\ob_get_clean(), '--enable-sigchild');
}

/**
Expand Down Expand Up @@ -420,15 +420,15 @@ private function pollExitCodePipe()
$r = array($this->sigchildPipe);
$w = $e = null;

$n = @stream_select($r, $w, $e, 0);
$n = @\stream_select($r, $w, $e, 0);

if (1 !== $n) {
return;
}

$data = fread($r[0], 8192);
$data = \fread($r[0], 8192);

if (strlen($data) > 0) {
if (\strlen($data) > 0) {
$this->fallbackExitCode = (int) $data;
}
}
Expand All @@ -444,7 +444,7 @@ private function closeExitCodePipe()
return;
}

fclose($this->sigchildPipe);
\fclose($this->sigchildPipe);
$this->sigchildPipe = null;
}

Expand Down Expand Up @@ -487,7 +487,7 @@ private function updateStatus()
return;
}

$this->status = proc_get_status($this->process);
$this->status = \proc_get_status($this->process);

if ($this->status === false) {
throw new \UnexpectedValueException('proc_get_status() failed');
Expand Down