Skip to content

Expose os, compiler, arch in php -v #19328

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 20 additions & 7 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,36 @@ ZEND_ATTRIBUTE_CONST PHPAPI const char *php_build_provider(void)

PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
{
zend_string *os = php_get_uname('s');
zend_string *os_version = php_get_uname('r');

smart_string version_info = {0};
smart_string_append_printf(&version_info,
"PHP %s (%s) (built: %s) (%s)\n",
"PHP %s (%s) (built: %s) (%s) (%s %s%s)\n",
PHP_VERSION, sapi_module->name, php_build_date,
#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_ARCH
" " PHP_BUILD_ARCH
#else
" Unknown arch"
#endif
,
ZSTR_VAL(os),
ZSTR_VAL(os_version),
#ifdef PHP_BUILD_COMPILER
" " PHP_BUILD_COMPILER
#else
" Unknown compiler"
#endif
);
smart_string_appends(&version_info, "Copyright (c) The PHP Group\n");
Expand All @@ -150,6 +160,9 @@ PHPAPI char *php_get_version(sapi_module_struct *sapi_module)
smart_string_appends(&version_info, get_zend_version());
smart_string_0(&version_info);

zend_string_free(os);
zend_string_free(os_version);

return version_info.c;
}

Expand Down
20 changes: 20 additions & 0 deletions main/php_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ PHPAPI bool php_tsrm_startup(void);
#define PHP_OS_STR PHP_OS
#endif

#ifndef PHP_BUILD_COMPILER
# if defined(__clang__)
/* __VERSION__ contains the compiler name */
# define PHP_BUILD_COMPILER __VERSION__
# elif defined(__GNUC__)
/* __VERSION__ does not contain the compiler name */
# define PHP_BUILD_COMPILER "GCC " __VERSION__
# endif
#endif

#ifndef PHP_BUILD_ARCH
# if defined(__x86_64__)
# define PHP_BUILD_ARCH "x86_64"
# elif defined(__i386__)
# define PHP_BUILD_ARCH "x86"
# elif defined(__aarch64__)
# define PHP_BUILD_ARCH "aarch64"
# endif
#endif

END_EXTERN_C()

#endif
Loading