diff --git a/phpmainthread.go b/phpmainthread.go index 5561cbd77..b1bcbd329 100644 --- a/phpmainthread.go +++ b/phpmainthread.go @@ -30,16 +30,18 @@ func initPHPThreads(numThreads int) error { } phpThreads = make([]*phpThread, numThreads) - if err := mainThread.start(); err != nil { - return err - } - // initialize all threads as inactive + // this needs to happen before starting the main thread + // since some extensions access environment variables on startup for i := 0; i < numThreads; i++ { phpThreads[i] = newPHPThread(i) convertToInactiveThread(phpThreads[i]) } + if err := mainThread.start(); err != nil { + return err + } + // start the underlying C threads ready := sync.WaitGroup{} ready.Add(numThreads) diff --git a/phpthread.go b/phpthread.go index 067e7d2c2..f8ad9b62a 100644 --- a/phpthread.go +++ b/phpthread.go @@ -73,11 +73,10 @@ func (thread *phpThread) getActiveRequest() *http.Request { // Pin a string that is not null-terminated // PHP's zend_string may contain null-bytes func (thread *phpThread) pinString(s string) *C.char { - if s == "" { + sData := unsafe.StringData(s) + if sData == nil { return nil } - - sData := unsafe.StringData(s) thread.Pin(sData) return (*C.char)(unsafe.Pointer(sData))