kitech / php-go Goto Github PK
View Code? Open in Web Editor NEWWrite PHP extension using go/golang. Zend API wrapper for go/golang.
Write PHP extension using go/golang. Zend API wrapper for go/golang.
3.2M -rw-rw-r-- 1 ubt ubt 3.2M 6月 5 07:14 hello.so
但是一般的原生扩展都很小,即便是swoole,才2MB不到。
1.8M -rwxr-xr-x 1 root root 1.8M 5月 25 00:00 swoole.so*
I ask you if with an extension can I override the whatever is of php that wrote errors to log file. I want to override it to directly parse and store into a local dB
Hi,
I ran make
under the project's dir, and got:
$ make
go install ./zend
# github.com/hyper-carrot/php-go/zend
In file included from zend/szend.c:10:
In file included from /usr/local/Cellar/php56/5.6.22/include/php/Zend/zend_API.h:26:
In file included from /usr/local/Cellar/php56/5.6.22/include/php/Zend/zend_modules.h:25:
In file included from /usr/local/Cellar/php56/5.6.22/include/php/Zend/zend.h:51:
In file included from /usr/local/Cellar/php56/5.6.22/include/php/Zend/zend_config.h:1:
In file included from /usr/local/Cellar/php56/5.6.22/include/php/main/../main/php_config.h:2530:
/usr/include/sys/types.h:92:23: error: cannot combine with previous 'int' declaration specifier
zend/sztypes.h:5:23: note: expanded from macro 'uint'
make: *** [all] Error 2
I don't know what is the matter. My Env:
OS: OS X 10.11.5
Go version: 1.6.1
PHP version: 5.6.22 (install with homebrew)
run examples/hello.php
show php warning:
Warning: Wrong parameter count for PGDemo::Hello1()
or show----
nginx error:
[error] 12199#0: *471 recv() failed (104: Connection reset by peer) while reading response header from upstream,
php version 5.6 nginx+php-fpm
go version 1.6
hi
i get error on make
go version go1.19.10 linux/amd64
centos 7 64 bit
[root@nginx php-go]# make
go install ./zend
# example.com/m/zend
zend/typeconv.go:31:26: could not determine kind of name for C.IS_CONSTANT
make: *** [all] Error 2
Hi, I've tried to build an extension on an ubuntu 16.04 server with go version go1.12.5 linux/amd64 and php version 5.6.40-6+ubuntu16.04.1+deb.sury.org+3 but got an error. With php 7 works perfectly (I've even tried on docker) but with php5.6 when I run
APP=/path/to/app PHPCFG=/usr/bin/php-config make
returns:
go install ./zend
# github.com/kitech/php-go/zend
zend/zend_ini.go:123:26: could not determine kind of name for C.uint32_t
Makefile:31: recipe for target 'all' failed
make: *** [all] Error 2
should I forgotten something?
Is it possible to use this library to write extensions for HHVM?
PHP 5.5.38 并没有 IS_CONSTANT_AS 常量,无法编译。PHP7正常。
.......
.......
strings
runtime/cgo
github.com/kitech/php-go/zend
# github.com/kitech/php-go/zend
In file included from zend/typeconv.go:9:
../zend/compat.h:25:2: error: #error "Maybe you are using not supported zend < 2.5.0 (PHP < 5.5.0)"
make: *** [all] Error 2
[root@GOtest php-go]# ls
[root@GOtest php-go]# grep -rl IS_CONSTANT_AST /usr/local/src/php-7.0.10/Zend/
/usr/local/src/php-7.0.10/Zend/zend_variables.c
/usr/local/src/php-7.0.10/Zend/zend_inheritance.c
/usr/local/src/php-7.0.10/Zend/zend_types.h
/usr/local/src/php-7.0.10/Zend/zend_ast.c
/usr/local/src/php-7.0.10/Zend/zend_execute_API.c
[root@GOtest php-go]# grep -rl IS_CONSTANT_AST /usr/local/php7/
/usr/local/php7/include/php/Zend/zend_types.h
[root@GOtest php-go]# grep -rl IS_CONSTANT_AST /usr/local/php5.5.38/
[root@GOtest php-go]# grep -rl IS_CONSTANT_AST /usr/local/src/php-5.5.38
[root@GOtest php-go]#
[root@GOtest php-go]# /usr/local/php5.5.38/bin/php -v
PHP 5.5.38 (cli) (built: Sep 7 2016 19:40:59)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
[root@GOtest php-go]#
PHP Warning: PHP Startup: Unable to load dynamic library './hello.so' - dlopen(./hello.so, 9): Symbol not found: _zval_used_for_init
Referenced from: ./hello.so
Expected in: flat namespace
in ./hello.so in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library './hello.so' - dlopen(./hello.so, 9): Symbol not found: _zval_used_for_init
Referenced from: ./hello.so
Expected in: flat namespace
in ./hello.so in Unknown on line 0
PHP Fatal error: Uncaught Error: Call to undefined function foo_hello() in /Users/robbin/go/src/github.com/kitech/php-go/examples/hello.php:5
Stack trace:
#0 /Users/robbin/go/src/github.com/kitech/php-go/examples/hello.php(58): test_funcs()
#1 {main}
thrown in /Users/robbin/go/src/github.com/kitech/php-go/examples/hello.php on line 5
Fatal error: Uncaught Error: Call to undefined function foo_hello() in /Users/robbin/go/src/github.com/kitech/php-go/examples/hello.php:5
Stack trace:
#0 /Users/robbin/go/src/github.com/kitech/php-go/examples/hello.php(58): test_funcs()
#1 {main}
thrown in /Users/robbin/go/src/github.com/kitech/php-go/examples/hello.php on line 5
And php 5.6 is ok
Excuse me, how to pass an array to an extension function parameter
That would be really interesting.
使用AddClass 返回struct时 执行 net.Dial net.DialTimeout net.DialTCP 会卡住 无响应
Listen端可以接收到创建好TCP.
不知道是否是我使用问题.
php 执行 命令行没有问题可以正常返回...
或者有什么能看到php-fpm子进程的输出吗
php-fpm -R -e -F (修改root执行.没有有用的信息输出)
How do you turn off all the print/log messages to actually use this as a module?
# make
go install ./zend
# github.com/kitech/php-go/zend
could not determine kind of name for C.IS_CONSTANT_AST
make: *** [all] Ошибка 2
Ubuntu 14.04.4
go version go1.6 linux/386
zend/typeconv.go:30:26: could not determine kind of name for C.IS_CONSTANT
How can i fix this?
var_dump(foo_hello3(1,"w",2.1));
报错位置
extension.c 330 行左右
printf("arg%d, type=%d\n", idx, Z_TYPE_PP(args[idx])); 这行有错误
Hi, I can't build it on my mac (10.13.4)
make failed with:
PHPCFG=/usr/local/bin/php-config make
go install ./zend
go build github.com/kitech/php-go/zend: invalid flag in #cgo LDFLAGS: -undefined
make: *** [all] Error 1
go version
go version go1.9.5 darwin/amd64
With 1.8 and 1.10 I had same result
php version
PHP 7.1.14 (cli) (built: Apr 23 2018 16:42:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.14, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
What I do wrong?
执行一次然后关闭然后快速的执行下一次奔溃
➜ php-go-test php -d extension=./examples.so main.php
[php -d extension=./examples.so main.php]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x10700efce]
goroutine 17 [running, locked to thread]:
github.com/kitech/php-go/phpgo.(*FuncEntry).IsGlobal(...)
/Users/mac-mini/go/src/github.com/kitech/php-go/phpgo/extension.go:63
github.com/kitech/php-go/phpgo.on_phpgo_function_callback_p(0xffffffffffffffff, 0x106c1f0d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/mac-mini/go/src/github.com/kitech/php-go/phpgo/extension.go:492 +0xace
github.com/kitech/php-go/phpgo._cgoexpwrap_845d1fe97f7e_on_phpgo_function_callback_p(0xffffffffffffffff, 0x106c1f0d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
github.com/kitech/php-go/phpgo/_obj/_cgo_gotypes.go:424 +0xdb
I am getting the error when to running the go get
Command used = go get github.com/kitech/php-go
"can't load package: package github.com/kitech/php-go: no buildable Go source files"
目前我的php版本是:PHP 7.1.2 (cli) (built: May 6 2019 14:06:43) ( NTS )
在cli模式下支持go协程运行,但是在php-fpm运行模式下就会阻塞。
readme.me 'function' => 'func'
I invoke sql`s query in golang func
when invoke in php(thinkphp) It return 504
why? how to resolve it.
thanks a lot.
does not support go 1.7
大佬吊炸天,能继续更新吗
压测的时候发现编译出来扩展性能比较慢, 不如原生的快.
Your example shows how to return an int
.
How would I return a string
?
../../github.com/kitech/php-go/zend/zend_ini.go:123: cannot use C.uint(len(name)) (type C.uint) as type C.uint32_t in assignment
../../github.com/kitech/php-go/zend/zend_ini.go:124: cannot use C.uint(len(value)) (type C.uint) as type C.uint32_t in assignment
../../github.com/kitech/php-go/zend/zend_ini.go:128: cannot use C.uint(len(name) + 1) (type C.uint) as type C.uint32_t in assignment
../../github.com/kitech/php-go/zend/zend_ini.go:129: cannot use C.uint(len(value) + 1) (type C.uint) as type C.uint32_t in assignment
PHP 7.2.0 类型不兼容
PHP 7.1.12 测试没有问题
many mounth ago!
Hi
First of all thanks for this library. When building an extension with PHP 5.6, I get the following error:
zend_ini.go:123:26: could not determine kind of name for C.uint32_t
I can fix it by adding #include <stdint.h>
in the cgo comments in that file.
Do you think you could apply this fix?
gcc: error: Usage:: No such file or directory
gcc: error: [OPTION]: No such file or directory
gcc: error: Options:: No such file or directory
gcc: error: [-I/home/php7/include/php: No such file or directory
gcc: error: []: No such file or directory
gcc: error: [-lcrypt: No such file or directory
gcc: error: ]: No such file or directory
gcc: error: [/home/php7/lib/php/extensions/no-debug-non-zts-20190902]: No such file or directory
gcc: error: [/home/php7/include/php]: No such file or directory
gcc: error: [/home/php7/php/man]: No such file or directory
gcc: error: [/home/php7/bin/php]: No such file or directory
gcc: error: [: No such file or directory
gcc: error: cli: No such file or directory
gcc: error: phpdbg: No such file or directory
gcc: error: cgi]: No such file or directory
gcc: error: [/home/php7/lib]: No such file or directory
gcc: error: []: No such file or directory
gcc: error: [--prefix=/home/php7]: No such file or directory
gcc: error: [7.4.27]: No such file or directory
gcc: error: [70427]: No such file or directory
gcc: error: unrecognized command line option '--includes'
gcc: error: unrecognized command line option '--ldflags'
gcc: error: unrecognized command line option '--libs'
gcc: error: unrecognized command line option '--extension-dir'
gcc: error: unrecognized command line option '--include-dir'
gcc: error: unrecognized command line option '--man-dir'
gcc: error: unrecognized command line option '--php-binary'
gcc: error: unrecognized command line option '--php-sapis'
gcc: error: unrecognized command line option '--ini-path'
gcc: error: unrecognized command line option '--ini-dir'
gcc: error: unrecognized command line option '--configure-options'
gcc: error: unrecognized command line option '--vernum'
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
cgo: cannot parse $WORK/b041/cgo.o as ELF, Mach-O, PE or XCOFF
How to build in Windows
I don't think (based on issues found in the golang repository) that we will see golang support for forking in shared c libraries anytime soon. If you fork and interact with golang objects and functions post-fork, you will eventually deadlock.
For example, in the current example.php
:
Take...
test_funcs();
test_classes();
test_inis();
And rewrite it work a fork, based on the example @ https://www.php.net/manual/en/function.pcntl-fork.php
test_funcs();
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
pcntl_wait($status); //Protect against Zombie children
} else {
$i=0;
while(true) {
test_classes();
echo($i++);
}
}
test_inis();
And you will see fairly quickly, it will deadlock. Here is a GIF:
Knowing that this probably won't fixable anytime soon, and from what I can tell, PHP doesn't offer support for unloading and reloading extensions during forking, maybe we should put up a notice about it in the README? Unless anybody know of a theoretical way around this, which I would be very grateful for.
macOS最新版,环境php7.3.2,go1.9.2
$ PHPCFG=/usr/local/Cellar/php/7.3.2/bin/php-config make
然后报错:
go install ./zend
# github.com/zywaited/php-go/zend
zend/typeconv.go:31:26: could not determine kind of name for C.IS_CONSTANT
make: *** [all] Error 2
go install ./zend
# errors
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# math/bits
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# runtime/internal/atomic
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# internal/cpu
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# runtime/internal/sys
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# internal/race
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# unicode/utf8
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# sync/atomic
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# unicode
compile: version "go1.12.9" does not match go tool version "go1.10.4"
# runtime/cgo
compile: version "go1.12.9" does not match go tool version "go1.10.4"
Makefile:31: recipe for target 'all' failed
make: *** [all] Error 2
$ make
make: /usr/bin/php-config: Command not found
make: /usr/bin/php-config: Command not found
make: /usr/bin/php-config: Command not found
make: /usr/bin/php-config: Command not found
go install ./zend
In file included from zend/goapi.go:5:0:
./array.h:1:10: fatal error: zend_API.h: No such file or directory
#include <zend_API.h>
^~~~~~~~~~~~
compilation terminated.
Makefile:31: recipe for target 'all' failed
make: *** [all] Error 2
Hello,
I was wondering if its possible to have some code in Go calling a callback in the PHP code. Example: If I set a socket server in Go I would like to be able to call a PHP function to handle incoming data whenever data is available.
Thank you.
PHP7 works great but when I try to compile on PHP 5 I get:
../../vendor/github.com/kitech/php-go/zend/szend.c: In function '_gozend_function_exists_ht':
../../vendor/github.com/kitech/php-go/zend/szend.c:189:2: error: unknown type name 'zend_string'
zend_string *name;
^
../../vendor/github.com/kitech/php-go/zend/szend.c:191:2: error: unknown type name 'zend_string'
zend_string *lcname;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.