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

Commit

Permalink
Merge branch 'hotfix/82-process-screen-width'
Browse files Browse the repository at this point in the history
Close #92
Fixes #82
  • Loading branch information
weierophinney committed Jun 25, 2018
2 parents 9a52cda + 2b52ab8 commit 7d048a4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ Releases prior to 1.2.0 did not have entries.

### Fixed

- [#92](https://github.com/zendframework/zenddiagnostics/pull/92) fixes how the `ProcessRunning` diagnostic works when given
a process name, but the current window is too small to display it (a problem
that only occurs on some operating systems).

- [#80](https://github.com/zendframework/zenddiagnostics/pull/80) fixes how the `MongoDB\Client` instance is created when using ext-mongodb + mongodb/mongodb,
ensuring it uses the provided connection URI.
46 changes: 34 additions & 12 deletions src/Check/ProcessRunning.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ProcessRunning extends AbstractCheck
* @var string
*/
private $processName;

/**
* @var int
*/
private $pid;

/**
Expand All @@ -45,14 +49,14 @@ public function __construct($processNameOrPid)
}

if (is_numeric($processNameOrPid)) {
if ((int)$processNameOrPid < 0) {
if ((int) $processNameOrPid < 0) {
throw new InvalidArgumentException(sprintf(
'Wrong argument provided for ProcessRunning check - ' .
'expected pid to be a positive number but got %s',
(int)$processNameOrPid
(int) $processNameOrPid
));
}
$this->pid = (int)$processNameOrPid;
$this->pid = (int) $processNameOrPid;
} else {
$this->processName = $processNameOrPid;
}
Expand All @@ -65,17 +69,35 @@ public function check()
{
// TODO: make more OS agnostic
if ($this->pid) {
exec('ps -p ' . (int)$this->pid, $output, $return);
return $this->checkAgainstPid();
}

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

if ($return == 1) {
return new Failure(sprintf('Could not find any running process containing "%s"', $this->processName));
}
/**
* @return \ZendDiagnostics\Result\ResultInterface
*/
private function checkAgainstPid()
{
exec('ps -p ' . (int) $this->pid, $output, $return);

if ($return == 1) {
return new Failure(sprintf('Process with PID %s is not currently running.', $this->pid));
}

return new Success();
}

/**
* @return \ZendDiagnostics\Result\ResultInterface
*/
private function checkAgainstProcessName()
{
exec('ps -efww | grep ' . escapeshellarg($this->processName) . ' | grep -v grep', $output, $return);

if ($return > 0) {
return new Failure(sprintf('Could not find any running process containing "%s"', $this->processName));
}

return new Success();
Expand Down

0 comments on commit 7d048a4

Please sign in to comment.