Skip to content

Commit 10cf2c4

Browse files
authored
fix: use the global logger during classes preloading (#1994)
* fix: use the global logger during classes preloading * better fix * fix comparision * Update frankenphp.go
1 parent f224f8e commit 10cf2c4

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

frankenphp.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,11 @@ func go_read_cookies(threadIndex C.uintptr_t) *C.char {
652652
//export go_log
653653
func go_log(threadIndex C.uintptr_t, message *C.char, level C.int) {
654654
ctx := phpThreads[threadIndex].context()
655+
655656
m := C.GoString(message)
657+
le := syslogLevelInfo
656658

657-
var le syslogLevel
658-
if level < C.int(syslogLevelEmerg) || level > C.int(syslogLevelDebug) {
659-
le = syslogLevelInfo
660-
} else {
659+
if level >= C.int(syslogLevelEmerg) && level <= C.int(syslogLevelDebug) {
661660
le = syslogLevel(level)
662661
}
663662

phpthread.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ func (thread *phpThread) shutdown() {
8282
func (thread *phpThread) setHandler(handler threadHandler) {
8383
thread.handlerMu.Lock()
8484
defer thread.handlerMu.Unlock()
85+
8586
if !thread.state.requestSafeStateChange(stateTransitionRequested) {
8687
// no state change allowed == shutdown or done
8788
return
8889
}
90+
8991
close(thread.drainChan)
9092
thread.state.waitFor(stateTransitionInProgress)
9193
thread.handler = handler
@@ -108,6 +110,11 @@ func (thread *phpThread) frankenPHPContext() *frankenPHPContext {
108110
}
109111

110112
func (thread *phpThread) context() context.Context {
113+
if thread.handler == nil {
114+
// handler can be nil when using opcache.preload
115+
return globalCtx
116+
}
117+
111118
return thread.handler.context()
112119
}
113120

threadinactive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (handler *inactiveThread) frankenPHPContext() *frankenPHPContext {
4848
}
4949

5050
func (handler *inactiveThread) context() context.Context {
51-
return nil
51+
return globalCtx
5252
}
5353

5454
func (handler *inactiveThread) name() string {

0 commit comments

Comments
 (0)