1
0
mirror of https://github.com/deuill/go-php.git synced 2024-09-21 00:40:45 +00:00
PHP bindings for the Go programming language (Golang)
Go to file
Alex Palaistras 6fa93f5160 First version of variable bindings to context.
This commit contains an initial version of variable bindings
to a context, along with tests. Currently supported types are
integers, floating point numbers, and strings.
2015-09-20 01:16:43 +01:00
test First version of variable bindings to context. 2015-09-20 01:16:43 +01:00
context_test.go First version of variable bindings to context. 2015-09-20 01:16:43 +01:00
context.c First version of variable bindings to context. 2015-09-20 01:16:43 +01:00
context.go First version of variable bindings to context. 2015-09-20 01:16:43 +01:00
context.h First version of variable bindings to context. 2015-09-20 01:16:43 +01:00
engine_test.go First version of variable bindings to context. 2015-09-20 01:16:43 +01:00
engine.c Move context write method to context.c. 2015-09-19 21:12:32 +01:00
engine.go First version of variable bindings to context. 2015-09-20 01:16:43 +01:00
engine.h Initial commit of entire workspace 2015-09-17 22:22:07 +01:00
LICENSE Initial commit of entire workspace 2015-09-17 22:22:07 +01:00
README.md Initial commit of entire workspace 2015-09-17 22:22:07 +01:00
value.c First version of variable bindings to context. 2015-09-20 01:16:43 +01:00
value.h First version of variable bindings to context. 2015-09-20 01:16:43 +01:00

PHP bindings for Go

This package implements bindings for calling PHP scripts and binding Go variables for use in PHP contexts.

Building

Building this package requires that you have PHP built and installed as a library. For most Linux systems, this would be a file under /usr/lib/libphp5.so, and usually exists in a package named php5-embed, or variations thereof.

Be aware that, by default, PHP is not designed to be used in multithreaded environments (which restricts the use of goroutines) if not built with ZTS support. Unfortunately, most distributions do not ship ZTS-enabled versions of PHP by default, and very few offer pre-compiled packages, so you're mostly left to compile one yourself.

That said, the Go PHP bindings can be used in Goroutines, with caution. Synchronization is left to the user.

Once the PHP library is available, the bindings can be compiled with go build and are go get-able.

Usage

Executing a script is very simple:

package main

import (
    "bytes"
    "os"

    php "github.com/deuill/go-php"
)

func main() {
    var b bytes.Buffer

    engine, _ := php.New()
    context, _ := engine.NewContext(&b)

    context.Exec("src/index.php")
    b.WriteTo(os.Stdout)
}

The above will execute script file located in src/index.php and write any output to the io.Writer passed to engine.NewContext.

By executing the PHP context in a goroutine, one can read from the writer as the output is generated by the script, and is useful for long-running scripts which output information during execution.

Status/Caveats

Currently, the bindings are incomplete and offer no variable binding capabilities. This functionality is underway, however.

State of tests and documentation are also terribly lacking.