Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e8e9e3

Browse files
committed
bug #21076 [Console] OS X Can't call cli_set_process_title php without superuser (ogizanagi)
This PR was merged into the 2.7 branch. Discussion ---------- [Console] OS X Can't call cli_set_process_title php without superuser | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A The console component test suite is failing on OS X (10.12.2) as the `cli_set_process_title` function seems not to be allowed to be called without superuser. It seems to be an OS X limitation. At least, the test suite should pass and a warning should be shown when using the component with this feature on OS X. --- refs: - http://stackoverflow.com/questions/27803120/cannot-set-process-title-in-a-php-command-line-script-using-cli-set-process-titl - liip/php-osx#139 - zfcampus/zf-console#22 Commits ------- 9928c0d [Console] OS X Can't call cli_set_process_title php without superuser
2 parents 6daebcb + 9928c0d commit 7e8e9e3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Symfony/Component/Console/Command/Command.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,14 @@ public function run(InputInterface $input, OutputInterface $output)
227227

228228
if (null !== $this->processTitle) {
229229
if (function_exists('cli_set_process_title')) {
230-
cli_set_process_title($this->processTitle);
230+
if (false === @cli_set_process_title($this->processTitle)) {
231+
if ('Darwin' === PHP_OS) {
232+
$output->writeln('<comment>Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.</comment>');
233+
} else {
234+
$error = error_get_last();
235+
trigger_error($error['message'], E_USER_WARNING);
236+
}
237+
}
231238
} elseif (function_exists('setproctitle')) {
232239
setproctitle($this->processTitle);
233240
} elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ public function testRunWithProcessTitle()
328328
$command->setProcessTitle('foo');
329329
$this->assertSame(0, $command->run(new StringInput(''), new NullOutput()));
330330
if (function_exists('cli_set_process_title')) {
331+
if (null === @cli_get_process_title() && 'Darwin' === PHP_OS) {
332+
$this->markTestSkipped('Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.');
333+
}
331334
$this->assertEquals('foo', cli_get_process_title());
332335
}
333336
}

0 commit comments

Comments
 (0)