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
9 changes: 8 additions & 1 deletion frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package frankenphp
// #include <php_variables.h>
// #include <zend_llist.h>
// #include <SAPI.h>
// static inline const char *frankenphp_get_build_version() {
// return TOSTRING(FRANKENPHP_VERSION);
// }
import "C"
import (
"bytes"
Expand Down Expand Up @@ -145,6 +148,10 @@ func Version() PHPVersion {
}
}

func frankenPHPVersion() string {
return C.GoString(C.frankenphp_get_build_version())
}
Comment thread
ousamabenyounes marked this conversation as resolved.

func Config() PHPConfig {
cConfig := C.frankenphp_get_config()

Expand Down Expand Up @@ -342,7 +349,7 @@ func Init(options ...Option) error {
initAutoScaling(mainThread)

if globalLogger.Enabled(globalCtx, slog.LevelInfo) {
globalLogger.LogAttrs(globalCtx, slog.LevelInfo, "FrankenPHP started 🐘", slog.String("php_version", Version().Version), slog.Int("num_threads", mainThread.numThreads), slog.Int("max_threads", mainThread.maxThreads), slog.Int("max_requests", maxRequestsPerThread))
globalLogger.LogAttrs(globalCtx, slog.LevelInfo, startupLogMessage, startupLogAttrs(Version().Version, mainThread.numThreads, mainThread.maxThreads, maxRequestsPerThread)...)

if EmbeddedAppPath != "" {
globalLogger.LogAttrs(globalCtx, slog.LevelInfo, "embedded PHP app 📦", slog.String("path", EmbeddedAppPath))
Expand Down
27 changes: 27 additions & 0 deletions startup_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package frankenphp

import "log/slog"

const (
startupLogMessage = "FrankenPHP started 🐘"
startupLogAttrVersion = "version"
startupLogAttrPHPVersion = "php_version"
startupLogAttrNumThreads = "num_threads"
startupLogAttrMaxThreads = "max_threads"
startupLogAttrMaxRequests = "max_requests"
startupLogAttrCapacity = 5
)

func startupLogAttrs(phpVersion string, numThreads int, maxThreads int, maxRequests int) []slog.Attr {
attrs := make([]slog.Attr, 0, startupLogAttrCapacity)
if version := frankenPHPVersion(); version != "" {
attrs = append(attrs, slog.String(startupLogAttrVersion, version))
}

return append(attrs,
slog.String(startupLogAttrPHPVersion, phpVersion),
slog.Int(startupLogAttrNumThreads, numThreads),
slog.Int(startupLogAttrMaxThreads, maxThreads),
slog.Int(startupLogAttrMaxRequests, maxRequests),
)
}
33 changes: 33 additions & 0 deletions startup_log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package frankenphp

import (
"os"
"testing"
)

const startupLogTestExpectedVersionEnv = "FRANKENPHP_EXPECT_VERSION"

func TestStartupLogAttrsIncludeFrankenPHPVersion(t *testing.T) {
const (
testPHPVersion = "8.2.31"
testNumThreads = 4
testMaxThreads = 8
testMaxRequests = 0
)

expectedFrankenPHPVersion := os.Getenv(startupLogTestExpectedVersionEnv)
if expectedFrankenPHPVersion == "" {
expectedFrankenPHPVersion = frankenPHPVersion()
}

attrs := startupLogAttrs(testPHPVersion, testNumThreads, testMaxThreads, testMaxRequests)
if len(attrs) == 0 {
t.Fatal("expected startup log attrs")
}
if attrs[0].Key != startupLogAttrVersion {
t.Fatalf("expected first startup log attr key %q, got %q", startupLogAttrVersion, attrs[0].Key)
}
if got := attrs[0].Value.String(); got != expectedFrankenPHPVersion {
t.Fatalf("expected startup log version %q, got %q", expectedFrankenPHPVersion, got)
}
}
Loading