{"record":{"id":"65580ef32f89f399","repo":"composer/composer","slug":"failed-to-execute-command-erroroutput-65580e","errorCode":null,"errorMessage":"Failed to execute {command}\n\n{errorOutput}","messagePattern":"Failed to execute (.+?)\n\n(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/Composer/Downloader/GzipDownloader.php","lineNumber":47,"sourceCode":"        $targetFilepath = $path . DIRECTORY_SEPARATOR . $filename;\n\n        // Try to use gunzip on *nix\n        if (!Platform::isWindows()) {\n            $command = ['sh', '-c', 'gzip -cd -- \"$0\" > \"$1\"', $file, $targetFilepath];\n\n            if (0 === $this->process->execute($command, $ignoredOutput)) {\n                return \\React\\Promise\\resolve(null);\n            }\n\n            if (extension_loaded('zlib')) {\n                // Fallback to using the PHP extension.\n                $this->extractUsingExt($file, $targetFilepath);\n\n                return \\React\\Promise\\resolve(null);\n            }\n\n            $processError = 'Failed to execute ' . implode(' ', $command) . \"\\n\\n\" . $this->process->getErrorOutput();\n            throw new \\RuntimeException($processError);\n        }\n\n        // Windows version of PHP has built-in support of gzip functions\n        $this->extractUsingExt($file, $targetFilepath);\n\n        return \\React\\Promise\\resolve(null);\n    }\n\n    private function extractUsingExt(string $file, string $targetFilepath): void\n    {\n        $archiveFile = gzopen($file, 'rb');\n        $targetFile = fopen($targetFilepath, 'wb');\n        while ($string = gzread($archiveFile, 4096)) {\n            fwrite($targetFile, $string, Platform::strlen($string));\n        }\n        gzclose($archiveFile);\n        fclose($targetFile);\n    }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/composer/composer/blob/6ffc1177404d0c50119c22dde6564a380f4a82c9/src/Composer/Downloader/GzipDownloader.php#L29-L65","documentation":"Thrown by GzipDownloader::extract() on non-Windows when the shell command `gzip -cd` fails AND the PHP zlib extension is not loaded. On non-Windows Composer first tries the system gzip binary; only if that fails does it fall back to ext-zlib. With neither available, extraction is impossible.","triggerScenarios":"Installing a package whose dist is a .gz single-file archive (not a tar/zip) on a minimal Linux image that lacks the gzip binary and where PHP was compiled without --enable-zlib.","commonSituations":"Minimal Alpine/Docker images without gzip installed; PHP images built without ext-zlib; stripped-down CI runners.","solutions":["Install gzip in the environment: apt-get install -y gzip (or apk add gzip on Alpine).","Enable/install the PHP zlib extension (ext-zlib) so the PHP fallback works.","Use a PHP image that ships ext-zlib (most official images do).","Prefer dist formats that use XzDownloader/TarDownloader if the provider offers non-gzip archives."],"exampleFix":"# before: neither gzip nor ext-zlib available\ncomposer install   # GzipDownloader fails\n\n# after: install gzip\napt-get update && apt-get install -y gzip\n# or ensure ext-zlib in PHP:\ndocker-php-ext-install zlib   # rebuild PHP with zlib","handlingStrategy":"validation","validationCode":"// Verify gzip binary or ext-zlib before relying on GzipDownloader\n$hasGzip = false === stripos(PHP_OS_FAMILY, 'Windows')\n    ? (function_exists('shell_exec') ? (bool) trim((string) shell_exec('command -v gzip')) : false)\n    : true; // Windows uses ext-zlib path\n$hasZlib = extension_loaded('zlib');\nif (!$hasGzip && !$hasZlib) {\n    throw new \\RuntimeException('No gzip extraction method available: install gzip or enable ext-zlib');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In Docker/CI images, install the gzip package (apk add gzip / apt-get install gzip).","Build PHP with --enable-zlib so the extension-level fallback is always present.","Prefer dist formats other than raw .gz where the provider offers tar.xz or zip."],"tags":["gzip","archive","zlib","binary-missing","php-extension"],"analyzedSha":"6ffc1177404d0c50119c22dde6564a380f4a82c9","analyzedAt":"2026-08-07T00:01:08.491Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}