kitech / php-go

Write PHP extension using go/golang. Zend API wrapper for go/golang.
882 stars 108 forks source link

使用 net.Dial 返回class时 php-fpm无响应 命令行可以执行 #30

Open sun8911879 opened 6 years ago

sun8911879 commented 6 years ago

使用AddClass 返回struct时 执行 net.Dial net.DialTimeout net.DialTCP 会卡住 无响应 Listen端可以接收到创建好TCP. 不知道是否是我使用问题. php 执行 命令行没有问题可以正常返回... 或者有什么能看到php-fpm子进程的输出吗 php-fpm -R -e -F (修改root执行.没有有用的信息输出)

sun8911879 commented 6 years ago

不使用 net.Dial net.DialTimeout net.DialTCP 就没这方面问题

kitech commented 6 years ago

谢谢关注。求PR。(搞的我像老板是的

sun8911879 commented 6 years ago

Go:

package main

import (
    "fmt"
    "net"
    "time"

    "github.com/kitech/php-go/phpgo"
)

type Bee struct {
    conn  net.Conn
    Error error
}

func init() {
    phpgo.InitExtension("go_demo", "1.0")
    phpgo.AddClass("Bee", NewBee)
    fmt.Println("[Go] php-go demo is run")
}

func main() { panic("wtf1") }

func NewBee() *Bee {
    return &Bee{}
}

func (b *Bee) Dial() bool {
    b.conn, b.Error = net.DialTimeout("tcp", "127.0.0.1:7463", time.Second)
    if b.Error != nil {
        return false
    }
    return true
}

func (b *Bee) Write() {
    //length 21
    b.conn.Write([]byte{84, 104, 105, 115, 32, 105, 115, 32, 110, 111, 116, 32, 97, 32, 100, 114, 105, 108, 108, 32, 33})
}

func (b *Bee) GetError() string {
    if b.Error == nil {
        return ""
    }
    return b.Error.Error()
}

func (b *Bee) Close() {
    b.conn.Close()
}

PHP:

<?php
    $bee = new Bee();
    if ($bee->Dial() == false) {
        echo $bee->GetError();
        exit;
    }
    $bee->Write();
    $bee->Close();
?>

测试环境 centos 6.9(虚拟机), PHP 7.1.12, PHP 7.2.0, Go: 1.9.2, Go: 1.8.5, Go: 1.8.2, Go: 1.10beta1

sun8911879 commented 6 years ago

请问还需要其他更详细的信息吗 您已经在处理了吗

kitech commented 6 years ago

刚改了一个小的编译问题,这个问题正在搞测试用例。顺便说下,准备把这个例子放在仓库的tests里,不要问我要版权就好。 如果你找到了解决办法,请随意PR。

sun8911879 commented 6 years ago

ok 不要版权.嗯 我也会找这个问题的解决办法.最近项目赶工期 可能不会有充足的时间来解决这个问题.