Skip to content

Commit 922de2d

Browse files
committed
feat: register phpinfo info entries under frankenphp extension
1 parent 3f43199 commit 922de2d

5 files changed

Lines changed: 47 additions & 2 deletions

File tree

caddy/caddy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/caddyserver/caddy/v2"
1111
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
12+
"github.com/dunglas/frankenphp"
1213
)
1314

1415
const (
@@ -26,6 +27,14 @@ func init() {
2627
caddy.RegisterModule(FrankenPHPModule{})
2728
caddy.RegisterModule(FrankenPHPAdmin{})
2829

30+
// Report Caddy version in phpinfo()
31+
simpleVersion, fullVersion := caddy.Version()
32+
if fullVersion != "" {
33+
frankenphp.AddPhpinfoEntry("Caddy Version", fullVersion)
34+
} else if simpleVersion != "" {
35+
frankenphp.AddPhpinfoEntry("Caddy Version", simpleVersion)
36+
}
37+
2938
httpcaddyfile.RegisterGlobalOption("frankenphp", parseGlobalOption)
3039

3140
httpcaddyfile.RegisterHandlerDirective("php", parseCaddyfile)

cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "unsafe"
99
func ExecuteScriptCLI(script string, args []string) int {
1010
// Ensure extensions are registered before CLI execution
1111
registerExtensions()
12+
initPhpinfoEntries()
1213

1314
cScript := C.CString(script)
1415
defer C.free(unsafe.Pointer(cScript))
@@ -22,6 +23,7 @@ func ExecuteScriptCLI(script string, args []string) int {
2223
func ExecutePHPCode(phpCode string) int {
2324
// Ensure extensions are registered before CLI execution
2425
registerExtensions()
26+
initPhpinfoEntries()
2527

2628
cCode := C.CString(phpCode)
2729
defer C.free(unsafe.Pointer(cCode))

frankenphp.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <errno.h>
77
#include <ext/spl/spl_exceptions.h>
88
#include <ext/standard/head.h>
9+
#include <ext/standard/info.h>
910
#ifdef HAVE_PHP_SESSION
1011
#include <ext/session/php_session.h>
1112
#endif
@@ -107,6 +108,8 @@ frankenphp_config frankenphp_get_config() {
107108
};
108109
}
109110

111+
const char **frankenphp_phpinfo_entries = NULL;
112+
110113
bool should_filter_var = 0;
111114
bool original_user_abort_setting = 0;
112115
frankenphp_interned_strings_t frankenphp_strings = {0};
@@ -1101,6 +1104,17 @@ PHP_MINIT_FUNCTION(frankenphp) {
11011104
return SUCCESS;
11021105
}
11031106

1107+
PHP_MINFO_FUNCTION(frankenphp) {
1108+
php_info_print_table_start();
1109+
php_info_print_table_row(2, "Version", TOSTRING(FRANKENPHP_VERSION));
1110+
if (frankenphp_phpinfo_entries) {
1111+
for (int i = 0; frankenphp_phpinfo_entries[i] != NULL; i += 2) {
1112+
php_info_print_table_row(2, frankenphp_phpinfo_entries[i], frankenphp_phpinfo_entries[i + 1]);
1113+
}
1114+
}
1115+
php_info_print_table_end();
1116+
}
1117+
11041118
static zend_module_entry frankenphp_module = {
11051119
STANDARD_MODULE_HEADER,
11061120
"frankenphp",
@@ -1109,7 +1123,7 @@ static zend_module_entry frankenphp_module = {
11091123
NULL, /* shutdown */
11101124
NULL, /* request initialization */
11111125
NULL, /* request shutdown */
1112-
NULL, /* information */
1126+
PHP_MINFO(frankenphp), /* information */
11131127
TOSTRING(FRANKENPHP_VERSION),
11141128
STANDARD_MODULE_PROPERTIES};
11151129

frankenphp.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
"time"
3838
"unsafe"
3939
// debug on Linux
40-
//_ "github.com/ianlancetaylor/cgosymbolizer"
40+
// _ "github.com/ianlancetaylor/cgosymbolizer"
4141
)
4242

4343
type contextKeyStruct struct{}
@@ -156,6 +156,22 @@ func Config() PHPConfig {
156156
}
157157
}
158158

159+
var phpinfoEntries []*C.char
160+
161+
func AddPhpinfoEntry(key, value string) {
162+
cKey := C.CString(key)
163+
cValue := C.CString(value)
164+
phpinfoEntries = append(phpinfoEntries, cKey, cValue)
165+
}
166+
167+
func initPhpinfoEntries() {
168+
if len(phpinfoEntries) == 0 {
169+
return
170+
}
171+
phpinfoEntries = append(phpinfoEntries, nil)
172+
C.frankenphp_phpinfo_entries = (**C.char)(unsafe.Pointer(&phpinfoEntries[0]))
173+
}
174+
159175
func calculateMaxThreads(opt *opt) (numWorkers int, _ error) {
160176
maxProcs := runtime.GOMAXPROCS(0) * 2
161177
maxThreadsFromWorkers := 0
@@ -250,6 +266,7 @@ func Init(options ...Option) error {
250266
signal.Ignore(syscall.SIGPIPE)
251267

252268
registerExtensions()
269+
initPhpinfoEntries()
253270

254271
opt := &opt{}
255272
for _, o := range options {

frankenphp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ typedef struct {
7474
#define STRINGIFY(x) #x
7575
#define TOSTRING(x) STRINGIFY(x)
7676

77+
/* phpinfo entries from Go - null-terminated array of key, value, key, value, ... */
78+
extern const char **frankenphp_phpinfo_entries;
79+
7780
typedef struct go_string {
7881
size_t len;
7982
char *data;

0 commit comments

Comments
 (0)