Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 7d048a4

Browse files
committed
Merge branch 'hotfix/82-process-screen-width'
Close #92 Fixes #82
2 parents 9a52cda + 2b52ab8 commit 7d048a4

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ Releases prior to 1.2.0 did not have entries.
4242

4343
### Fixed
4444

45+
- [#92](https://github.com/zendframework/zenddiagnostics/pull/92) fixes how the `ProcessRunning` diagnostic works when given
46+
a process name, but the current window is too small to display it (a problem
47+
that only occurs on some operating systems).
48+
4549
- [#80](https://github.com/zendframework/zenddiagnostics/pull/80) fixes how the `MongoDB\Client` instance is created when using ext-mongodb + mongodb/mongodb,
4650
ensuring it uses the provided connection URI.

src/Check/ProcessRunning.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class ProcessRunning extends AbstractCheck
2020
* @var string
2121
*/
2222
private $processName;
23+
24+
/**
25+
* @var int
26+
*/
2327
private $pid;
2428

2529
/**
@@ -45,14 +49,14 @@ public function __construct($processNameOrPid)
4549
}
4650

4751
if (is_numeric($processNameOrPid)) {
48-
if ((int)$processNameOrPid < 0) {
52+
if ((int) $processNameOrPid < 0) {
4953
throw new InvalidArgumentException(sprintf(
5054
'Wrong argument provided for ProcessRunning check - ' .
5155
'expected pid to be a positive number but got %s',
52-
(int)$processNameOrPid
56+
(int) $processNameOrPid
5357
));
5458
}
55-
$this->pid = (int)$processNameOrPid;
59+
$this->pid = (int) $processNameOrPid;
5660
} else {
5761
$this->processName = $processNameOrPid;
5862
}
@@ -65,17 +69,35 @@ public function check()
6569
{
6670
// TODO: make more OS agnostic
6771
if ($this->pid) {
68-
exec('ps -p ' . (int)$this->pid, $output, $return);
72+
return $this->checkAgainstPid();
73+
}
6974

70-
if ($return == 1) {
71-
return new Failure(sprintf('Process with PID %s is not currently running.', $this->pid));
72-
}
73-
} else {
74-
exec('ps -ef | grep ' . escapeshellarg($this->processName) . ' | grep -v grep', $output, $return);
75+
return $this->checkAgainstProcessName();
76+
}
7577

76-
if ($return == 1) {
77-
return new Failure(sprintf('Could not find any running process containing "%s"', $this->processName));
78-
}
78+
/**
79+
* @return \ZendDiagnostics\Result\ResultInterface
80+
*/
81+
private function checkAgainstPid()
82+
{
83+
exec('ps -p ' . (int) $this->pid, $output, $return);
84+
85+
if ($return == 1) {
86+
return new Failure(sprintf('Process with PID %s is not currently running.', $this->pid));
87+
}
88+
89+
return new Success();
90+
}
91+
92+
/**
93+
* @return \ZendDiagnostics\Result\ResultInterface
94+
*/
95+
private function checkAgainstProcessName()
96+
{
97+
exec('ps -efww | grep ' . escapeshellarg($this->processName) . ' | grep -v grep', $output, $return);
98+
99+
if ($return > 0) {
100+
return new Failure(sprintf('Could not find any running process containing "%s"', $this->processName));
79101
}
80102

81103
return new Success();

0 commit comments

Comments
 (0)