-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
golang defined php class not available after context destroy #30
Comments
package bug
import (
"fmt"
"github.com/deuill/go-php/engine"
"os"
"runtime"
"testing"
)
type TestObj struct{}
func newTestObj(args []interface{}) interface{} {
return &TestObj{}
}
func Test_bug(t *testing.T) {
runtime.GOMAXPROCS(1)
theEngine, err := engine.New()
if err != nil {
t.Fail()
}
fmt.Println("1")
context1, err := theEngine.NewContext()
if err != nil {
t.Fail()
}
recv1, err := theEngine.Define("TestObj", newTestObj)
if err != nil {
t.Fail()
}
fmt.Println("enter")
_, err = context1.Eval("$testObj = new TestObj();")
fmt.Println("back")
if err != nil {
t.Fail()
}
recv1.Destroy()
context1.Destroy()
fmt.Println("1 done")
fmt.Println("2")
context2, err := theEngine.NewContext()
if err != nil {
t.Fail()
}
recv2, err := theEngine.Define("TestObj", newTestObj)
if err != nil {
t.Fail()
}
context2.Output = os.Stdout
fmt.Println("enter")
_, err = context2.Eval("$testObj = new TestObj();")
fmt.Println("back")
if err != nil {
t.Fail()
}
recv2.Destroy()
context2.Destroy()
fmt.Println("2 done")
fmt.Println("all done")
} hack engine define to allow re-define the receiver again seems fixed the problem func (e *Engine) Define(name string, fn func(args []interface{}) interface{}) (*Receiver, error) {
//if _, exists := e.receivers[name]; exists {
// return fmt.Errorf("Failed to define duplicate receiver '%s'", name)
//} It seems like the |
Interesting, I'll check it out and see if I can make a quick fix for this. |
can not reproduce the bug in php 7 with static linking, interesting |
The semantics between destroying PHP requests (i.e. contexts) and modules (i.e. engines) are different between version 5.x and 7.x... I've had quite a few headaches trying to resolve issues where PHP would segfault for seemingly no apparent reason, when implementing the above code. The reason I've attached the I'll add some test cases like the above and see if I can reproduce the issue. |
I've been running variations of the above and cannot reproduce, on ArchLinux x64, PHP version 7.0.12. I'm gonna open a PR with tests covering the above and take it from there. |
I was able to reproduce this locally both with PHP5 and PHP7 - the receiver is only available sometimes. With 7.1 and onwards, I fixed the receiver issue for myself by creating a fake module that handles registration inside I can publish my changes in case there's interest, but it will have to be a separate repo as I've spliced the code to have PHP 5 with ZTS but also containing changes from 0.11. |
Any contribution would be welcome -- noted that PHP 5.x support is probably going to be phased out. Also noted that PHP 7.4 has a new FFI which may help integration, as the internals are moving targets, and as you may have surmised, not that stable/easy to integrate against. |
DEV-102 DEV-234 DEV-235 Add Dockerfile for gameserver Approved-by: Matthew Tyas <[email protected]>
The code will exit with 255. The php error log says
However, if we change the code to
it finishes without any problem, and the output to console is:
Which means the
TestObj
class definition is not actually completely gone, after context1 destroyed.The text was updated successfully, but these errors were encountered: