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 8a2ce468e2 Add documentation blocks.
Added documentation blocks and licence headers to all files.
2015-10-04 19:28:44 +01:00
.tests Move tests to hidden folder. 2015-09-22 22:06:35 +01:00
context Add documentation blocks. 2015-10-04 19:28:44 +01:00
engine Add documentation blocks. 2015-10-04 19:28:44 +01:00
value Add documentation blocks. 2015-10-04 19:28:44 +01:00
LICENSE Initial commit of entire workspace 2015-09-17 22:22:07 +01:00
php_test.go Add documentation blocks. 2015-10-04 19:28:44 +01:00
php.go Add documentation blocks. 2015-10-04 19:28:44 +01:00
README.md Add documentation blocks. 2015-10-04 19:28:44 +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 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 (
    "os"
    php "github.com/deuill/go-php"
)

func main() {
    engine, _ := php.New()
    context, _ := php.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 php.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

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.