mirror of
https://github.com/dunglas/frankenphp
synced 2024-11-23 08:39:21 +00:00
1c3ce114f6
Co-authored-by: Alliballibaba <alliballibaba@gmail.com> Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package frankenphp
|
|
|
|
// #include <stdint.h>
|
|
// #include <php_variables.h>
|
|
import "C"
|
|
import (
|
|
"net/http"
|
|
"runtime"
|
|
"unsafe"
|
|
)
|
|
|
|
var phpThreads []*phpThread
|
|
|
|
type phpThread struct {
|
|
runtime.Pinner
|
|
|
|
mainRequest *http.Request
|
|
workerRequest *http.Request
|
|
worker *worker
|
|
requestChan chan *http.Request
|
|
knownVariableKeys map[string]*C.zend_string
|
|
}
|
|
|
|
func initPHPThreads(numThreads int) {
|
|
phpThreads = make([]*phpThread, 0, numThreads)
|
|
for i := 0; i < numThreads; i++ {
|
|
phpThreads = append(phpThreads, &phpThread{})
|
|
}
|
|
}
|
|
|
|
func (thread phpThread) getActiveRequest() *http.Request {
|
|
if thread.workerRequest != nil {
|
|
return thread.workerRequest
|
|
}
|
|
|
|
return thread.mainRequest
|
|
}
|
|
|
|
// Pin a string that is not null-terminated
|
|
// PHP's zend_string may contain null-bytes
|
|
func (thread *phpThread) pinString(s string) *C.char {
|
|
sData := unsafe.StringData(s)
|
|
thread.Pin(sData)
|
|
return (*C.char)(unsafe.Pointer(sData))
|
|
}
|
|
|
|
// C strings must be null-terminated
|
|
func (thread *phpThread) pinCString(s string) *C.char {
|
|
return thread.pinString(s+"\x00")
|
|
}
|