Skip to content

Commit 6a6dda5

Browse files
authored
feat: expose PHP version (#102)
1 parent f0b2eb7 commit 6a6dda5

5 files changed

Lines changed: 56 additions & 1 deletion

File tree

caddy/caddy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (f *FrankenPHPApp) Start() error {
8282
}
8383
}
8484

85-
logger.Info("FrankenPHP started 🐘")
85+
logger.Info("FrankenPHP started 🐘", zap.String("php_version", frankenphp.Version().Version))
8686

8787
return nil
8888
}

frankenphp.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ static const char *MODULES_TO_RELOAD[] = {
3434
NULL
3535
};
3636

37+
frankenphp_php_version frankenphp_version() {
38+
return (frankenphp_php_version){
39+
PHP_MAJOR_VERSION,
40+
PHP_MINOR_VERSION,
41+
PHP_RELEASE_VERSION,
42+
PHP_EXTRA_VERSION,
43+
PHP_VERSION,
44+
PHP_VERSION_ID,
45+
};
46+
}
47+
3748
int frankenphp_check_version() {
3849
#ifndef ZTS
3950
return -1;

frankenphp.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ func FromContext(ctx context.Context) (fctx *FrankenPHPContext, ok bool) {
162162
return
163163
}
164164

165+
type PHPVersion struct {
166+
MajorVersion int
167+
MinorVersion int
168+
ReleaseVersion int
169+
ExtraVersion string
170+
Version string
171+
VersionID int
172+
}
173+
174+
// Version returns infos about the PHP version.
175+
func Version() PHPVersion {
176+
cVersion := C.frankenphp_version()
177+
178+
return PHPVersion{
179+
int(cVersion.major_version),
180+
int(cVersion.minor_version),
181+
int(cVersion.release_version),
182+
C.GoString(cVersion.extra_version),
183+
C.GoString(cVersion.version),
184+
int(cVersion.version_id),
185+
}
186+
}
187+
165188
// Init starts the PHP runtime and the configured workers.
166189
func Init(options ...Option) error {
167190
if requestChan != nil {

frankenphp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
#include <stdint.h>
55
#include <Zend/zend_types.h>
66

7+
typedef struct frankenphp_php_version {
8+
int major_version;
9+
int minor_version;
10+
int release_version;
11+
const char *extra_version;
12+
const char *version;
13+
int version_id;
14+
} frankenphp_php_version;
15+
16+
frankenphp_php_version frankenphp_version();
717
int frankenphp_check_version();
818
int frankenphp_init(int num_threads);
919

frankenphp_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,17 @@ func testFlush(t *testing.T, opts *testOptions) {
593593
assert.Equal(t, 2, j)
594594
}, opts)
595595
}
596+
597+
func TestVersion(t *testing.T) {
598+
v := frankenphp.Version()
599+
600+
assert.GreaterOrEqual(t, v.MajorVersion, 8)
601+
assert.GreaterOrEqual(t, v.MinorVersion, 0)
602+
assert.GreaterOrEqual(t, v.ReleaseVersion, 0)
603+
assert.GreaterOrEqual(t, v.VersionID, 0)
604+
assert.NotEmpty(t, v.Version, 0)
605+
}
606+
596607
func ExampleServeHTTP() {
597608
if err := frankenphp.Init(); err != nil {
598609
panic(err)

0 commit comments

Comments
 (0)