Skip to content

Show build provider and unify version information printing #14657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,47 @@ PHPAPI unsigned int php_version_id(void)
return PHP_VERSION_ID;
}

PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
{
char *version_info;
spprintf(&version_info, 0, "PHP %s (%s) (built: %s %s) (%s)\nCopyright (c) The PHP Group\n%s%s",
PHP_VERSION, sapi_module->name, __DATE__, __TIME__,
#ifdef ZTS
"ZTS"
#else
"NTS"
#endif
#ifdef PHP_BUILD_COMPILER
" " PHP_BUILD_COMPILER
#endif
#ifdef PHP_BUILD_ARCH
" " PHP_BUILD_ARCH
#endif
#if ZEND_DEBUG
" DEBUG"
#endif
#ifdef HAVE_GCOV
" GCOV"
#endif
,
#ifdef PHP_BUILD_PROVIDER
"Built by " PHP_BUILD_PROVIDER "\n"
#else
""
#endif
,
get_zend_version()
);
return version_info;
}

PHPAPI void php_print_version(sapi_module_struct *sapi_module)
{
char *version_info = php_get_version(sapi_module);
php_printf("%s", version_info);
efree(version_info);
}

/* {{{ PHP_INI_MH */
static PHP_INI_MH(OnSetFacility)
{
Expand Down
6 changes: 6 additions & 0 deletions main/php_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ PHPAPI const char *php_version(void);
*/
PHPAPI unsigned int php_version_id(void);

/* Prints the PHP version string for the -v option. It's in main/ so that
* it can be shared between SAPIs.
*/
PHPAPI char *php_get_version(sapi_module_struct *sapi_module);
PHPAPI void php_print_version(sapi_module_struct *sapi_module);

PHPAPI zend_result php_request_startup(void);
PHPAPI void php_request_shutdown(void *dummy);
PHPAPI zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_module);
Expand Down
6 changes: 1 addition & 5 deletions sapi/cgi/cgi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2377,11 +2377,7 @@ consult the installation file that came with this distribution, or visit \n\
}
SG(headers_sent) = 1;
SG(request_info).no_headers = 1;
#if ZEND_DEBUG
php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#else
php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#endif
php_print_version(&cgi_sapi_module);
php_request_shutdown((void *) 0);
fcgi_shutdown();
exit_status = 0;
Expand Down
2 changes: 1 addition & 1 deletion sapi/cgi/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ echo "Done\n";
--EXPECTF--
string(%d) "PHP %s (cgi%s (built: %s
Copyright (c) The PHP Group
Zend Engine v%s, Copyright (c) Zend Technologies
%AZend Engine v%s, Copyright (c) Zend Technologies
"
Done
23 changes: 1 addition & 22 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,28 +625,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
goto out;

case 'v': /* show php version & quit */
php_printf("PHP %s (%s) (built: %s %s) (%s)\nCopyright (c) The PHP Group\n%s",
PHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__,
#ifdef ZTS
"ZTS"
#else
"NTS"
#endif
#ifdef PHP_BUILD_COMPILER
" " PHP_BUILD_COMPILER
#endif
#ifdef PHP_BUILD_ARCH
" " PHP_BUILD_ARCH
#endif
#if ZEND_DEBUG
" DEBUG"
#endif
#ifdef HAVE_GCOV
" GCOV"
#endif
,
get_zend_version()
);
php_print_version(&cli_sapi_module);
sapi_deactivate();
goto out;

Expand Down
2 changes: 1 addition & 1 deletion sapi/cli/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ echo "Done\n";
--EXPECTF--
string(%d) "PHP %s (cli) (built: %s)%s
Copyright (c) The PHP Group
Zend Engine v%s, Copyright (c) Zend Technologies
%AZend Engine v%s, Copyright (c) Zend Technologies
"
Done
6 changes: 1 addition & 5 deletions sapi/fpm/fpm/fpm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1705,11 +1705,7 @@ int main(int argc, char *argv[])
SG(headers_sent) = 1;
SG(request_info).no_headers = 1;

#if ZEND_DEBUG
php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#else
php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#endif
php_print_version(&sapi_module);
php_request_shutdown((void *) 0);
fcgi_shutdown();
exit_status = FPM_EXIT_OK;
Expand Down
6 changes: 1 addition & 5 deletions sapi/litespeed/lsapi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1272,11 +1272,7 @@ static int cli_main( int argc, char * argv[] )
break;
case 'v':
if (php_request_startup() != FAILURE) {
#if ZEND_DEBUG
php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#else
php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
#endif
php_print_version(&sapi_module);
#ifdef PHP_OUTPUT_NEWAPI
php_output_end_all();
#else
Expand Down
17 changes: 9 additions & 8 deletions sapi/phpdbg/phpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "phpdbg_arginfo.h"
#include "zend_vm.h"
#include "php_ini_builder.h"
#include "php_main.h"

#include "ext/standard/basic_functions.h"

Expand Down Expand Up @@ -1369,14 +1370,14 @@ int main(int argc, char **argv) /* {{{ */
if (show_help) {
phpdbg_do_help_cmd(exec);
} else if (show_version) {
phpdbg_out(
"phpdbg %s (built: %s %s)\nPHP %s, Copyright (c) The PHP Group\n%s",
PHPDBG_VERSION,
__DATE__,
__TIME__,
PHP_VERSION,
get_zend_version()
);
char *version_info = php_get_version(&phpdbg_sapi_module);
/* we also want to include phpdbg version */
char *prepended_version_info;
spprintf(&prepended_version_info, 0,
"phpdbg %s, %s", PHPDBG_VERSION, version_info);
phpdbg_out("%s", prepended_version_info);
efree(prepended_version_info);
efree(version_info);
}
PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
php_module_shutdown();
Expand Down
Loading