Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128364 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 7B5A11A00BC for ; Fri, 1 Aug 2025 16:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1754065081; bh=CHj7YXwkD8VuPo68nNTW72+teN6v8zM0xiYhxU35KcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C4VzMx8WHK9SMlrJwvd0OK3r/Pw1eUPFw1nNp8jVBlx2JwuAIcOpwb5Y8oxQbVrUM fCuhqOn6ysYlwHN9nOGwa8kBl7zSxz5kFaHVvo06HPbThfUY4p0y/x5XZfvgtWLcnI uFWnPq5rhsliR16O5++/PfYmQ3Vyy9kGYrPwDf9xQMfxC+UgwStt/1Gx+9ZacnNJMa Ccy2itbh4aYct3zQwICf14qhmdTPb8qN7n7qLhDiuo6W4ao9xe/yLwzP1VOBkQL0gs K6zo6wSdJBTddRDmFqCv0UG9J7OYXZtLnOlvchfjj+Ck487Krm7ATnZCEovMhYbC2M MVvL77nusdxgA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AD0BC18003B for ; Fri, 1 Aug 2025 16:17:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from sonic.asd.mail.yahoo.com (sonic312-26.consmr.mail.ir2.yahoo.com [77.238.178.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 1 Aug 2025 16:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1754065178; bh=o5+1HV2OSNtCIzGuKDRsZBGnAd5LSi6ebfNk7hV1Ce8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=DKdskGTyygpN6C6iPzVuZnRQ2yOJGkfkHwc3YPkHVrUHX2tldi/iO/dbfth9VeiF81koull4BRwcZF4rZ1xDXlqjwgFuTnTc6g4bSRUy2WSjQE+MX73ZJwrTkGki6BRQnmdLILobMXmGbkiH86+A0cLVmMs3MwSn7x6W8qs+4iGSNuwTw4Zrgc+q0UlN1AcRAX3tb6tzsz7ZZKD0IaOazqF2fVPqvHSlc32F8BDFekIjhSs7XSJ6qBI1o5FWE1Ls3QTBe7F0HbindYJynhN67/QCu2gEavC3nU+cDM2OdSr6SvtSkmh6mlCSY6uwS0AcxrDjYRRZQHN7YJkpMTkxMA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1754065178; bh=NfKF5HO/L73iOWFKG3+Zz9vo+8Wa0GcKYzGvTyBHhYk=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=Sq7HLC6gZFmMS3P+jvJ4sAIGE7kRSiV7Tlzvb/3oD6SCsOlwwMcKRkoeZ/Buyhxu2u5lfHqR6XTW6j75iVVzS/6LIXK4W4QFYG6yWWvMHgFaripR6BR45B+Vnqd76wkr56E0BZzsrB1GifzqUkIl/e/5IVkxXcTrQfUJR5mdD4IllLpUMuJxkV0bpmSnIXU/z1aSlrugRd/zwO1pMSfBzHjWdsSCbQd5dOj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lNYyKEJrKmQTVIL slPXXxVjlv8BfEgM96Y46ACreTQT2d3stFEwJrsyO8_iNoLpWbBY9fpi7IHNSBALD96az1bMJLnK o95NwWdSBWMAAQX7o.YK1WAfupTvA8ya5dez8AoJzNX1aWsaRZd8mivvqamhs1_WAseYEbCgYiRg 9HypgYB329KDhCVG5hWkNbURqUNSbYkSfyPhy1WGEb0o7o6rGs0TWz38j_wuEzgQh4AKp2raPGHz FgcoVRYMvsfuVLMtxSBcbtST3hCXA6geO4.D2HLkVtx4CmCdDmHD23iY7CnzBKA54IfI- X-Sonic-MF: X-Sonic-ID: 33085a7c-cf4b-411e-9768-b257ec938959 Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Fri, 1 Aug 2025 16:19:38 +0000 Received: by hermes--production-ir2-858bd4ff7b-q7k6m (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 6aea928f3967be0113126988658b5d22; Fri, 01 Aug 2025 16:19:33 +0000 (UTC) Content-Type: text/plain; charset=utf-8; format=flowed Message-ID: <1754055407326.2742915832.1385540561@yahoo.de> To: xepozzd@gmail.com Cc: PHP internals Subject: Re: [PHP-DEV] [DISCUSSION] Json version of PHP Info Date: Fri, 01 Aug 2025 16:19:33 +0000 In-Reply-To: References: X-Mailer: Vivaldi Mail User-Agent: Vivaldi Mail/7.5.3735.56 Content-Transfer-Encoding: 7bit Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 From: hanskrentel@yahoo.de (Hans Krentel) On Tuesday 29 July 2025 09:12:13 (+02:00), Dmitry Derepko wrote: > Hi, Internals! > > I want to have a unified function phpinfo() for any environment. > > Currently phpinfo works different in CLI and SAPI modes: > - SAPI mode enforces the function print HTML tags > - CLI mode enforces the function print text as is > > Here is implementation of the function: > https://github.com/xepozz/php-src/blob/5dd9b0dcef229c55f67044537b076c6e4320f28c/ext/standard/info.c#L760 > > So I'd like to create a separate function phpinfo_json() which will dump > pretty much the same text as a json structure. > Use-case as simple as absurd: > - PHP/php -S serves the content as a SAPI mode > - RoadRunner/Queues/Workers which run PHP scripts as `php index.php` run it > as CLI mode > > It's not convenient to see CLI-like output when you run a web server. > It's not possible to fetch some info from the function output > User should write parsers for both function variations: SAPI and CLI to > parse something > There is no need to use the output buffers to get the information. > > New function output could be an array-like structure or a json string. It's > open to discuss. I'm okay with any or even both with a flag "$asArray" > Hello Dmitry, Reading about your improvement suggestion and wanted to share some feedback and commentary. IIRC both the internal webserver (since 5.4) and the CLI interface (since 5.0/1?) are a SAPI module of their own, packaged into the PHP cli binary. As on the CLI SAPI it makes very little sense to have HTML output, and the CLI-SERVER SAPI actually serves under the default_mimetype directive which is text/html, it is available in the hypermedia format. That only for clarification that both are SAPI modules and the reason why you (and me) see a difference is because a SAPI module can tell it's own preference whether it wants to have shown the phpinfo() as HTML or text. 1.) Format is controlled by the SAPI module 2.) The only option a SAPI module has is to say it prefers text over the HTML. This is the difference we see and that struck you as inconvenient. What you are asking for as I understand it is an alternative format controlled by the language user, not the SAPI module. So that it is always available regardless which preference a SAPI module has. I think application/json would be a good choice of such an additional / alternative user format for both kind of SAPI modules you are mentioning in your example. And I can imagine as well for most if not all of the other existing SAPI modules (dbg?), but that is likely to be checked when you prepare the implementation as all SAPI modules need to be able to interact with the PHP information, same as all PHP extensions need to do. Right now your suggestion covers one example for a SAPI module that prefers text (php_sapi_name "cli") and another one that does not (php_sapi_name "cli-server"), and both would get an additional phpinfo() format. I think this is a great idea, and I would love to see even more integrated support, e.g. `php -j` (free choice of mine for the example) on the command-line gives you the JSON output, pipe it to jq, gron or what not. Same requesting a phpinfo() index.php with an accept-media-type application/json giving the JSON, I won't complain about, not at all. Quick checks for provisioning scripts that the new binary is running? Configuration updates worked as intended? If you're looking forward to also bring some bonus to the table, it would be great if there is a JSON format for ini settings/directives introspection. not only their names, configuration defaults, runtime defaults and current values (as there is in phpinfo() already and in array form with other information functions), but also of which type an ini setting is, like does it require/supports quoting of value or not, the exact schema per setting (IIRC bool, number, string, quoted string, and some have enum type like multiple known values that do fold, e.g. 0 off 1 stdout 2 stderr + ini-bool for display_errors) Existing PHP scripts out there in the wild (Composer, Phpunit etc.) have the problem when invoking PHP_BINARY they are grabbing all ini settings to simulate the configuration but fail to address the correct encoding of the ini settings. My educated guess is that happens because the PHP information functions do not provide these important details as for the classic SAPIs each instance was configured, so the dynamic information processing never needed. Now 30 years later we do see the trend that you also describe that PHP scripts are invoking PHP scripts more dynamically and have some introspection, e.g. gathering the PHP information and then working with it. Mind thought, that I only note it down here as your example remembered me of that and what I know is missing in that regard. It may not be feasible and how I read your example / proposal not part of it. That is also why I wrote "bonus", mind the feature creep and this likely needs more research and perhaps gathering some data from sources, so likely not within your original scope. And you are right: If every one re-invents the wheel and writes a phpinfo() output parser (your project has a vendor folder above 1.5MiB size? most likely you have at least one of such libraries in there) instead of addressing it at the source. Ah, and perhaps consider to align with the existing interface. The phpinfo() function has flags, e.g. phpinfo(INFO_ALL | INFO_JSON_ALL_THE_THINGS) would be great, but others more clever than me would need to chime in as the current default INFO_ALL is -1 (~0) so setting all flags but INFO_JSON_ALL_THE_THINGS should not be automatically set because that wouldn't be backwards compatible. It's likely possible to solve, but I don't know about the code style and internals about such things. Out of my guts, I would not recommend to add another phpinfo_XXX() function for the JSON format but solely extend the the existing interface. Just my 2 cents -- hakre