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-17 19:53:26 +01:00
.tests Move tests to hidden folder. 2015-09-22 22:06:35 +01:00
context Move NewContext function to engine package 2015-10-16 14:42:15 +01:00
engine Move NewContext function to engine package 2015-10-16 14:42:15 +01:00
value Add struct-to-object value bindings 2015-10-17 16:00:16 +01:00
LICENSE Initial commit of entire workspace 2015-09-17 22:22:07 +01:00
php_test.go Add struct-to-object value bindings 2015-10-17 16:00:16 +01:00
php.go Move NewContext function to engine package 2015-10-16 14:42:15 +01:00
README.md Add docs and license badges for README 2015-10-17 19:53:26 +01:00

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

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

    context.Exec("index.php")

    engine.Destroy()
}

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.

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.