PHP bindings for the Go programming language (Golang)
Go to file
Alex Palaistras a4ab33b4d0 Clarify EditorConfig for Markdown files 2015-12-27 00:52:38 +00:00
.tests Move tests to hidden folder. 2015-09-22 22:06:35 +01:00
context Fix compiler warnings for context bindings 2015-12-16 21:22:45 +00:00
engine Simplify receiver_property_exists proxy function 2015-12-19 13:54:35 +00:00
value Merge branch 'master' into feature/define-method-receivers 2015-12-18 13:28:24 +00:00
.editorconfig Clarify EditorConfig for Markdown files 2015-12-27 00:52:38 +00:00
LICENSE Initial commit of entire workspace 2015-09-17 22:22:07 +01:00
README.md Make sure README example actually runs 2015-12-01 22:10:28 +00:00
php.go Move `NewContext` function to `engine` package 2015-10-16 14:42:15 +01:00
php_test.go Allow for property existence checks on method receivers 2015-12-18 23:19:25 +00:00

README.md

PHP bindings for Go API Documentation MIT License

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 can usually be found in the php5-embed package, or variations thereof.

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 (
    php "github.com/deuill/go-php"
    "os"
)

func main() {
    engine, _ := php.New()

    context, _ := engine.NewContext()
    context.Output = os.Stdout

    context.Exec("index.php")
    engine.Destroy()
}

The above will execute script file index.php located in the current folder and will write any output to the io.Writer assigned to Context.Output (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

Currently, execution of script files as well as code snippets has been implemented, as well as binding of most base types from Go to PHP contexts.

Calling Go functions and creating classes from Go method receivers is currently a work in progress.

A test-suite is included, which covers most common uses of this library.

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.

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.

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.