diff --git a/frankenphp.go b/frankenphp.go index 3a66fcaf..4b5c0972 100644 --- a/frankenphp.go +++ b/frankenphp.go @@ -652,12 +652,11 @@ func go_read_cookies(threadIndex C.uintptr_t) *C.char { //export go_log func go_log(threadIndex C.uintptr_t, message *C.char, level C.int) { ctx := phpThreads[threadIndex].context() - m := C.GoString(message) - var le syslogLevel - if level < C.int(syslogLevelEmerg) || level > C.int(syslogLevelDebug) { - le = syslogLevelInfo - } else { + m := C.GoString(message) + le := syslogLevelInfo + + if level >= C.int(syslogLevelEmerg) && level <= C.int(syslogLevelDebug) { le = syslogLevel(level) } diff --git a/phpthread.go b/phpthread.go index ec807be9..7c66f2b7 100644 --- a/phpthread.go +++ b/phpthread.go @@ -82,10 +82,12 @@ func (thread *phpThread) shutdown() { func (thread *phpThread) setHandler(handler threadHandler) { thread.handlerMu.Lock() defer thread.handlerMu.Unlock() + if !thread.state.requestSafeStateChange(stateTransitionRequested) { // no state change allowed == shutdown or done return } + close(thread.drainChan) thread.state.waitFor(stateTransitionInProgress) thread.handler = handler @@ -108,6 +110,11 @@ func (thread *phpThread) frankenPHPContext() *frankenPHPContext { } func (thread *phpThread) context() context.Context { + if thread.handler == nil { + // handler can be nil when using opcache.preload + return globalCtx + } + return thread.handler.context() } diff --git a/threadinactive.go b/threadinactive.go index 50172e57..06d89168 100644 --- a/threadinactive.go +++ b/threadinactive.go @@ -48,7 +48,7 @@ func (handler *inactiveThread) frankenPHPContext() *frankenPHPContext { } func (handler *inactiveThread) context() context.Context { - return nil + return globalCtx } func (handler *inactiveThread) name() string {