这个包实现了对执行PHP脚本、导出Go变量以便在PHP上下文中使用、将Go方法接收器附加为PHP类以及返回PHP变量以便在Go上下文中使用的支持。
支持PHP 5.x and PHP 7.x
编译
构建这个包需要将PHP作为库安装。对于大多数Linux系统,这通常可以在“php-embed”包或其变体中找到。 确保PHP库可用,就可以使用“go build”编译绑定,并且可以使用“go get”。
php5
This is due to the fact that PHP 7.x is the default build target.
Status
Executing PHP [script files] as well as [inline strings]is supported and stable.
interface{}
struct
Caveats
Be aware that, by default, PHP is not designed to be used in multithreaded environments (which severely restricts the use of these bindings with Goroutines) if not built with ZTS support. However, ZTS support has seen major refactoring between PHP 5 and PHP 7, and as such is currently unsupported by this package.
Currently, it is recommended to either sync use of seperate Contexts between Goroutines, or share a single Context among all running Goroutines.
Roadmap
Currently, the package lacks in several respects:
- ZTS/multi-threading support. This basically means using Go-PHP in Goroutines is severely limited.
- Documentation and examples, both package-level and external.
- Performance. There's no reason to believe Go-PHP suffers from any serious performance issues in particular, but adding benchmarks, especially compared against vanilla PHP, might help.
- Your feature request here?
These items will be tackled in order of significance (which may not be the order shown above).
Usage
Basic
Executing a script is simple:
index.phpio.WriterContext.Output
Binding and returning variables
The following example demonstrates binding a Go variable to the running PHP context, and returning a PHP variable for use in Go:
Context.Bindvar$varContext.Eval
interface{}Value.Interface()Value.String()
License
All code in this repository is covered by the terms of the MIT License, the full text of which can be found in the LICENSE file.