diff --git a/ext/standard/VmProcess.php b/ext/standard/VmProcess.php index 1004a498b48..a0bfc2c40c9 100644 --- a/ext/standard/VmProcess.php +++ b/ext/standard/VmProcess.php @@ -18,12 +18,9 @@ final class VmProcess */ public static function getrusage(int $who = 0) { - $raw = false; - if (VmGetrusageNative::available()) { - $raw = VmGetrusageNative::getrusage($who); - } elseif (\function_exists('getrusage')) { - $raw = @\getrusage($who); - } + $raw = VmGetrusageNative::available() + ? VmGetrusageNative::getrusage($who) + : false; if (false === $raw) { return false; } diff --git a/ext/standard/VmProcessIdentity.php b/ext/standard/VmProcessIdentity.php index 3c3a828edc6..588253a8d10 100644 --- a/ext/standard/VmProcessIdentity.php +++ b/ext/standard/VmProcessIdentity.php @@ -8,6 +8,7 @@ * Process identity builtins (issue #6119, native libc #7891). * * php-src: ext/standard/basic_functions.c — getmyuid, getmygid, get_current_user. + * No host \\posix_* / \\get*() delegation — libc FFI only (pairs #7287 getrusage shrink). */ final class VmProcessIdentity { @@ -19,12 +20,6 @@ public static function getmyuid(): int return $uid; } } - if (\function_exists('posix_getuid')) { - return (int) \posix_getuid(); - } - if (\function_exists('getuid')) { - return (int) \getuid(); - } throw new \LogicException('getmyuid() requires POSIX support in this compiler build'); } @@ -37,12 +32,6 @@ public static function getmygid(): int return $gid; } } - if (\function_exists('posix_getgid')) { - return (int) \posix_getgid(); - } - if (\function_exists('getgid')) { - return (int) \getgid(); - } throw new \LogicException('getmygid() requires POSIX support in this compiler build'); } @@ -58,24 +47,6 @@ public static function getCurrentUser(): string } } } - $euid = null; - if (\function_exists('posix_geteuid')) { - $euid = (int) \posix_geteuid(); - } elseif (\function_exists('geteuid')) { - $euid = (int) \geteuid(); - } - if (null !== $euid && \function_exists('posix_getpwuid')) { - $pw = @\posix_getpwuid($euid); - if (\is_array($pw) && isset($pw['name']) && '' !== $pw['name']) { - return (string) $pw['name']; - } - } - if (null !== $euid && \function_exists('getpwuid')) { - $pw = @\getpwuid($euid); - if (\is_object($pw) && isset($pw->pw_name) && '' !== $pw->pw_name) { - return (string) $pw->pw_name; - } - } return 'Unknown'; } diff --git a/test/unit/VmGetrusageNativeTest.php b/test/unit/VmGetrusageNativeTest.php index 8572ef6086c..06ecdf64427 100644 --- a/test/unit/VmGetrusageNativeTest.php +++ b/test/unit/VmGetrusageNativeTest.php @@ -17,6 +17,8 @@ public function testVmProcessPrefersNativeOverHostDelegation(): void $this->assertStringContainsString('VmGetrusageNative::available()', $source); $this->assertStringContainsString('VmGetrusageNative::getrusage', $source); $this->assertStringNotContainsString('host libc via Zend PHP', $source); + $this->assertStringNotContainsString("function_exists('getrusage')", $source); + $this->assertDoesNotMatchRegularExpression('/\\\\getrusage\\s*\\(/', $source); } public function testNativeDefinesLibcGetrusageFfi(): void diff --git a/test/unit/VmProcessIdentityNativeTest.php b/test/unit/VmProcessIdentityNativeTest.php index 7fd606ecb59..24366fc6216 100644 --- a/test/unit/VmProcessIdentityNativeTest.php +++ b/test/unit/VmProcessIdentityNativeTest.php @@ -19,6 +19,13 @@ public function testVmProcessIdentityPrefersNativeOverHostDelegation(): void $this->assertStringContainsString('VmProcessIdentityNative::getgid()', $source); $this->assertStringContainsString('VmProcessIdentityNative::geteuid()', $source); $this->assertStringContainsString('VmProcessIdentityNative::getpwuidName', $source); + $this->assertStringNotContainsString("function_exists('posix_", $source); + $this->assertStringNotContainsString("function_exists('getuid')", $source); + $this->assertStringNotContainsString("function_exists('getgid')", $source); + $this->assertStringNotContainsString("function_exists('geteuid')", $source); + $this->assertStringNotContainsString("function_exists('getpwuid')", $source); + $this->assertDoesNotMatchRegularExpression('/\\\\posix_[a-z_]+\\(/', $source); + $this->assertDoesNotMatchRegularExpression('/\\\\getpwuid\\s*\\(/', $source); } public function testVmDateGetmygrgidUsesProcessIdentity(): void