Skip to content
Open
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
17 changes: 17 additions & 0 deletions caddy/br.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@

package caddy

import (
"runtime/debug"

"github.com/dunglas/frankenphp"
)

var brotli = true

func init() {
if buildInfo, ok := debug.ReadBuildInfo(); ok {
for _, dep := range buildInfo.Deps {
if dep.Path == "github.com/dunglas/caddy-cbrotli" {
frankenphp.AddPhpinfoEntry("dunglas/caddy-cbrotli", dep.Version)
break
}
}
}
}
9 changes: 9 additions & 0 deletions caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/dunglas/frankenphp"
)

const (
Expand All @@ -26,6 +27,14 @@ func init() {
caddy.RegisterModule(FrankenPHPModule{})
caddy.RegisterModule(FrankenPHPAdmin{})

// Report Caddy version in phpinfo()
simpleVersion, fullVersion := caddy.Version()
if fullVersion != "" {
frankenphp.AddPhpinfoEntry("caddy", fullVersion)
} else if simpleVersion != "" {
frankenphp.AddPhpinfoEntry("caddy", simpleVersion)
}

httpcaddyfile.RegisterGlobalOption("frankenphp", parseGlobalOption)

httpcaddyfile.RegisterHandlerDirective("php", parseCaddyfile)
Expand Down
2 changes: 2 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "unsafe"
func ExecuteScriptCLI(script string, args []string) int {
// Ensure extensions are registered before CLI execution
registerExtensions()
initPhpinfoEntries()

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

cCode := C.CString(phpCode)
defer C.free(unsafe.Pointer(cCode))
Expand Down
17 changes: 16 additions & 1 deletion frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <errno.h>
#include <ext/spl/spl_exceptions.h>
#include <ext/standard/head.h>
#include <ext/standard/info.h>
#ifdef HAVE_PHP_SESSION
#include <ext/session/php_session.h>
#endif
Expand Down Expand Up @@ -107,6 +108,8 @@ frankenphp_config frankenphp_get_config() {
};
}

const char **frankenphp_phpinfo_entries = NULL;

bool should_filter_var = 0;
bool original_user_abort_setting = 0;
frankenphp_interned_strings_t frankenphp_strings = {0};
Expand Down Expand Up @@ -1101,6 +1104,18 @@ PHP_MINIT_FUNCTION(frankenphp) {
return SUCCESS;
}

PHP_MINFO_FUNCTION(frankenphp) {
php_info_print_table_start();
php_info_print_table_row(2, "frankenphp", TOSTRING(FRANKENPHP_VERSION));
if (frankenphp_phpinfo_entries) {
for (int i = 0; frankenphp_phpinfo_entries[i] != NULL; i += 2) {
php_info_print_table_row(2, frankenphp_phpinfo_entries[i],
frankenphp_phpinfo_entries[i + 1]);
}
}
php_info_print_table_end();
}

static zend_module_entry frankenphp_module = {
STANDARD_MODULE_HEADER,
"frankenphp",
Expand All @@ -1109,7 +1124,7 @@ static zend_module_entry frankenphp_module = {
NULL, /* shutdown */
NULL, /* request initialization */
NULL, /* request shutdown */
NULL, /* information */
PHP_MINFO(frankenphp), /* information */
TOSTRING(FRANKENPHP_VERSION),
STANDARD_MODULE_PROPERTIES};

Expand Down
47 changes: 46 additions & 1 deletion frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ import (
"os"
"os/signal"
"runtime"
"sort"
"strings"
"sync"
"sync/atomic"
"syscall"
"time"
"unsafe"
// debug on Linux
//_ "github.com/ianlancetaylor/cgosymbolizer"
// _ "github.com/ianlancetaylor/cgosymbolizer"
)

type contextKeyStruct struct{}
Expand Down Expand Up @@ -156,6 +157,49 @@ func Config() PHPConfig {
}
}

type phpinfoEntry struct {
key, value string
}

var (
phpinfoEntries []phpinfoEntry
cPhpinfoArr []*C.char
)

func AddPhpinfoEntry(key, value string) {
phpinfoEntries = append(phpinfoEntries, phpinfoEntry{key, value})
}

func initPhpinfoEntries() {
for _, cstr := range cPhpinfoArr {
if cstr != nil {
C.free(unsafe.Pointer(cstr))
}
}
if cPhpinfoArr != nil {
C.free(unsafe.Pointer(&cPhpinfoArr[0]))
cPhpinfoArr = nil
C.frankenphp_phpinfo_entries = nil
}

if len(phpinfoEntries) == 0 {
return
}

sort.Slice(phpinfoEntries, func(i, j int) bool {
return phpinfoEntries[i].key < phpinfoEntries[j].key
})

n := 2*len(phpinfoEntries) + 1
cPhpinfoArr = (*[1 << 28]*C.char)(C.malloc(C.size_t(n) * C.size_t(unsafe.Sizeof(uintptr(0)))))[:n:n]
for i, e := range phpinfoEntries {
cPhpinfoArr[2*i] = C.CString(e.key)
cPhpinfoArr[2*i+1] = C.CString(e.value)
}
cPhpinfoArr[n-1] = nil
C.frankenphp_phpinfo_entries = &cPhpinfoArr[0]
}

func calculateMaxThreads(opt *opt) (numWorkers int, _ error) {
maxProcs := runtime.GOMAXPROCS(0) * 2
maxThreadsFromWorkers := 0
Expand Down Expand Up @@ -250,6 +294,7 @@ func Init(options ...Option) error {
signal.Ignore(syscall.SIGPIPE)

registerExtensions()
initPhpinfoEntries()

opt := &opt{}
for _, o := range options {
Expand Down
4 changes: 4 additions & 0 deletions frankenphp.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ typedef struct {
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

/* phpinfo entries from Go - null-terminated array of key, value, key, value,
* ... */
extern const char **frankenphp_phpinfo_entries;

typedef struct go_string {
size_t len;
char *data;
Expand Down
12 changes: 12 additions & 0 deletions mercure.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ package frankenphp
import "C"
import (
"log/slog"
"runtime/debug"
"unsafe"

"github.com/dunglas/mercure"
)

func init() {
if buildInfo, ok := debug.ReadBuildInfo(); ok {
for _, dep := range buildInfo.Deps {
if dep.Path == "github.com/dunglas/mercure" {
AddPhpinfoEntry("dunglas/mercure", dep.Version)
break
}
}
}
}

type mercureContext struct {
mercureHub *mercure.Hub
}
Expand Down
13 changes: 13 additions & 0 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
package frankenphp

import (
"runtime/debug"
"sync/atomic"

"github.com/dunglas/frankenphp/internal/watcher"
watcherGo "github.com/e-dant/watcher/watcher-go"
)

func init() {
// watcher doesn't expose the version, so get it from go.mod
if buildInfo, ok := debug.ReadBuildInfo(); ok {
for _, dep := range buildInfo.Deps {
if dep.Path == "github.com/e-dant/watcher" {
AddPhpinfoEntry("e-dant/watcher", dep.Version)
break
}
}
}
}

type hotReloadOpt struct {
hotReload []*watcher.PatternGroup
}
Expand Down
Loading