Skip to content

Commit 991fa8b

Browse files
committed
phpinfo improvements
- "Zstd support enabled" doesn't provide any information, so just remove it - show if zstd is bundled or not - show if zstd is the active serializer for apcu or if apcu isn't loaded - rename serializer ABI to interface, which is consistent with zstd interface - if apcu support wasn't built, show that it could have been built
1 parent 3ef892e commit 991fa8b

4 files changed

Lines changed: 94 additions & 12 deletions

File tree

‎config.m4‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ if test "$PHP_ZSTD" != "no"; then
8989

9090
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/zstd/lib/common)
9191
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/zstd/lib)
92+
AC_DEFINE(HAVE_BUNDLED_ZSTD, 1, [Bundled zstd])
9293
fi
9394
PHP_NEW_EXTENSION(zstd, zstd.c $ZSTD_COMMON_SOURCES $ZSTD_COMPRESS_SOURCES $ZSTD_DECOMPRESS_SOURCES, $ext_shared,, [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
9495
PHP_SUBST(ZSTD_SHARED_LIBADD)

‎config.w32‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ if (PHP_ZSTD != "no") {
2323
ADD_SOURCES("zstd/lib/compress", "fse_compress.c hist.c huf_compress.c zstd_compress.c zstd_compress_literals.c zstd_compress_sequences.c zstd_compress_superblock.c zstd_double_fast.c zstd_fast.c zstd_lazy.c zstd_ldm.c zstd_opt.c zstd_preSplit.c zstdmt_compress.c", "zstd");
2424
ADD_SOURCES("zstd/lib/decompress", "huf_decompress.c zstd_ddict.c zstd_decompress.c zstd_decompress_block.c", "zstd");
2525

26+
AC_DEFINE("HAVE_BUNDLED_ZSTD", 1, "Bundled zstd");
27+
2628
ADD_FLAG("CFLAGS_ZSTD", " /I" + configure_module_dirname + " /I" + configure_module_dirname + "/zstd/lib/common" + " /I" + configure_module_dirname + "/zstd/lib");
2729
}
2830
}

‎tests/info.phpt‎

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,75 @@ phpinfo() displays zstd info
33
--SKIPIF--
44
--FILE--
55
<?php
6-
phpinfo();
7-
--EXPECTF--
8-
%a
9-
zstd
6+
$ref = new ReflectionExtension('zstd');
7+
ob_start();
8+
$ref->info();
9+
$info = ob_get_contents();
10+
ob_end_clean();
11+
12+
// skip uninteresting lines
13+
$lines = [];
14+
foreach(explode("\n", $info) as $line) {
15+
if ($line && $line !== 'zstd') {
16+
$lines[] = $line;
17+
}
18+
}
19+
20+
$verNum = '(([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{1,2}))';
21+
22+
if (count($lines) >= 4) {
23+
echo preg_match('/^Extension\sversion\s\=\>\s'.$verNum.'$/', $lines[0]) ? "Ext version OK\n" : "Fail\n";
24+
25+
$libZstd = '(bundled|external)';
26+
$hasApcu = null;
27+
28+
if (file_exists($configH = dirname(__DIR__) . '/config.h')) {
29+
$configH = file_get_contents($configH);
30+
$libZstd = preg_match('/define\sHAVE_BUNDLED_ZSTD\s1/', $configH) ? 'bundled' : 'external';
31+
$hasApcu = preg_match('/define\sHAVE_APCU_SUPPORT\s1/', $configH) ? true : false;
32+
}
33+
34+
echo preg_match('/^Zstd\slibrary\s\=\>\s'.$libZstd.'$/', $lines[1]) ? "Bundled/external zstd OK\n" : "Fail\n";
1035

11-
Zstd support => enabled
12-
Extension Version => %d.%d.%d
13-
Interface Version => %d.%d.%d
14-
%a
36+
echo preg_match('/^Zstd\sinterface\sversion\s\=\>\s'.$verNum.'$/', $lines[2]) ? "Zstd version OK\n" : "Fail\n";
37+
38+
if ($hasApcu === null) {
39+
echo "Apcu OK\n"; // just assume it is okay
40+
} else if ($hasApcu) {
41+
if (substr($lines[3], 0, 18) !== 'APCu serializer =>') {
42+
echo "Fail\n";
43+
} else {
44+
$fail = '';
45+
$value = substr($lines[3], 19);
46+
47+
if (!extension_loaded('apcu')) {
48+
if ($value !== 'APCu extension not loaded') {
49+
$fail .= 'should be not loaded ';
50+
}
51+
} else if (!in_array($value, ['zstd active', 'zstd inactive'])) {
52+
$fail .= 'active/inactive mismatch ';
53+
}
54+
55+
if (
56+
!isset($lines[4])
57+
||
58+
!preg_match('/^APCu\sserializer\sinterface\sversion\s\=\>\s([0-9])/', $lines[4])
59+
) {
60+
$fail .= 'ABI ';
61+
}
62+
63+
echo !$fail ? "Apcu OK\n" : ("Fail: " . $fail . "");
64+
}
65+
} else {
66+
echo ($lines[3] == 'APCu serializer support => not built') ? "Apcu OK\n" : "Fail: not built\n";
67+
}
68+
69+
/**
70+
* TODO: test built-in header exclusion list
71+
**/
72+
}
73+
--EXPECTF--
74+
Ext version OK
75+
Bundled/external zstd OK
76+
Zstd version OK
77+
Apcu OK

‎zstd.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,11 +1943,27 @@ ZEND_RSHUTDOWN_FUNCTION(zstd)
19431943
ZEND_MINFO_FUNCTION(zstd)
19441944
{
19451945
php_info_print_table_start();
1946-
php_info_print_table_row(2, "Zstd support", "enabled");
1947-
php_info_print_table_row(2, "Extension Version", PHP_ZSTD_VERSION);
1948-
php_info_print_table_row(2, "Interface Version", ZSTD_VERSION_STRING);
1946+
php_info_print_table_row(2, "Extension version", PHP_ZSTD_VERSION);
1947+
#if defined(HAVE_BUNDLED_ZSTD)
1948+
php_info_print_table_row(2, "Zstd library", "bundled");
1949+
#else
1950+
php_info_print_table_row(2, "Zstd library", "external");
1951+
#endif
1952+
php_info_print_table_row(2, "Zstd interface version", ZSTD_VERSION_STRING);
19491953
#if defined(HAVE_APCU_SUPPORT)
1950-
php_info_print_table_row(2, "APCu serializer ABI", APC_SERIALIZER_ABI);
1954+
const char *serializer = zend_ini_string("apc.serializer", sizeof("apc.serializer")-1, 0);
1955+
1956+
if (serializer == NULL) {
1957+
php_info_print_table_row(2, "APCu serializer", "APCu extension not loaded");
1958+
} else if (strcmp(serializer, "zstd") == 0) {
1959+
php_info_print_table_row(2, "APCu serializer", "zstd active");
1960+
} else {
1961+
php_info_print_table_row(2, "APCu serializer", "zstd inactive");
1962+
}
1963+
1964+
php_info_print_table_row(2, "APCu serializer interface version", APC_SERIALIZER_ABI);
1965+
#else
1966+
php_info_print_table_row(2, "APCu serializer support", "not built");
19511967
#endif
19521968
php_info_print_table_end();
19531969
DISPLAY_INI_ENTRIES();

0 commit comments

Comments
 (0)