Skip to content
Write PHP extension using go/golang. Zend API wrapper for go/golang.
Branch: master
Clone or download
Latest commit e7fb0bd Mar 8, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples My 2 cents Apr 24, 2018
phpgo support PHP Jan 23, 2019
zend support PHP Jan 23, 2019
.gitignore My 2 cents Apr 24, 2018
Makefile My 2 cents Apr 24, 2018 My 2 cents Apr 24, 2018

GoDoc GoDoc


Write PHP extension using go/golang. Zend API wrapper for go/golang.

Simple, easy, fun to write PHP extensions.


  • function support
  • struct/class support
  • constant support
  • primitive data type as parameters and return values, (u)int*/float*/string/bool
  • complex data type as parameters, map/slice/array
  • all can be done by programmatic


  • Modern Linux/Unix system
  • PHP 5.5+/7.x
  • go version 1.4+
  • php5-dev installed (apt-get install php5-dev)
  • for MacOS, go 1.8+

Build & Install

go get:

go get
cd $GOPATH/src/
# adjust PHPCFG path if needed
PHPCFG=`which php-config` make


mkdir -p $GOPATH/src/
git clone $GOPATH/src/
cd $GOPATH/src/
ls -lh php-go/
php56 -d extension=./ examples/hello.php


// package main is required
package main

import ""

func foo_in_go() {

type Bar struct{}
func NewBar() *Bar{
    return &Bar{}

func init() {
    phpgo.InitExtension("mymod", "1.0")

    phpgo.AddFunc("foo_in_php", foo_in_go)
    phpgo.AddClass("bar_in_php", NewBar)

// should not run this function
// required for go build though.
func main() { panic("wtf") }


  • install with go get
  • improve php7 support
  • namespace support
  • multiple extension support
  • class member access support
  • unlimited function/method/class count support
  • global ini var support
  • fill phpinfo


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
You can’t perform that action at this time.