Skip to content

Commit 8e08e21

Browse files
authored
Merge pull request #68 from WyriHaximus-labs/function-name-look-up-performance-improvement
Improve performance by prefixing all global functions calls with \ to skip the look up and resolve process and go straight to the global function
2 parents 6ad670c + 4cd9267 commit 8e08e21

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/Process.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Process extends EventEmitter
7575
*/
7676
public function __construct($cmd, $cwd = null, array $env = null, array $fds = null)
7777
{
78-
if (!function_exists('proc_open')) {
78+
if (!\function_exists('proc_open')) {
7979
throw new \LogicException('The Process class relies on proc_open(), which is not available on your PHP installation.');
8080
}
8181

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

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

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

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

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

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

@@ -233,7 +233,7 @@ public function close()
233233
$this->closeExitCodePipe();
234234
}
235235

236-
$exitCode = proc_close($this->process);
236+
$exitCode = \proc_close($this->process);
237237
$this->process = null;
238238

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

265265
if ($signal !== null) {
266-
return proc_terminate($this->process, $signal);
266+
return \proc_terminate($this->process, $signal);
267267
}
268268

269-
return proc_terminate($this->process);
269+
return \proc_terminate($this->process);
270270
}
271271

272272
/**
@@ -385,10 +385,10 @@ public final static function isSigchildEnabled()
385385
return self::$sigchild;
386386
}
387387

388-
ob_start();
389-
phpinfo(INFO_GENERAL);
388+
\ob_start();
389+
\phpinfo(INFO_GENERAL);
390390

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

394394
/**
@@ -420,15 +420,15 @@ private function pollExitCodePipe()
420420
$r = array($this->sigchildPipe);
421421
$w = $e = null;
422422

423-
$n = @stream_select($r, $w, $e, 0);
423+
$n = @\stream_select($r, $w, $e, 0);
424424

425425
if (1 !== $n) {
426426
return;
427427
}
428428

429-
$data = fread($r[0], 8192);
429+
$data = \fread($r[0], 8192);
430430

431-
if (strlen($data) > 0) {
431+
if (\strlen($data) > 0) {
432432
$this->fallbackExitCode = (int) $data;
433433
}
434434
}
@@ -444,7 +444,7 @@ private function closeExitCodePipe()
444444
return;
445445
}
446446

447-
fclose($this->sigchildPipe);
447+
\fclose($this->sigchildPipe);
448448
$this->sigchildPipe = null;
449449
}
450450

@@ -487,7 +487,7 @@ private function updateStatus()
487487
return;
488488
}
489489

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

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

0 commit comments

Comments
 (0)