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
2015-10-02 18:17:12 +01:00
.tests Re-organize and merge test files 2015-10-02 18:07:57 +01:00
context Fix incorrect TSRMLS_FETCH call 2015-10-02 18:12:42 +01:00
engine Re-organize and merge test files 2015-10-02 18:07:57 +01:00
value Split code into seperate directories. 2015-10-02 00:48:33 +01:00
LICENSE Initial commit of entire workspace 2015-09-17 22:22:07 +01:00
php_test.go Re-organize and merge test files 2015-10-02 18:07:57 +01:00
php.go Re-organize and merge test files 2015-10-02 18:07:57 +01:00
README.md Fix incorrect reference in README. 2015-09-22 22:07:26 +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 (
    "os"
    php "github.com/deuill/go-php"
)

func main() {
    engine, _ := php.New()
    context, _ := engine.NewContext(os.Stdout)

    context.Exec("index.php")
}

The above will execute script file located in index.php and write any output to the io.Writer passed to engine.NewContext (in this case, the standard output).

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.