• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    C
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

php-go allows to call Go code from PHP, with minimal code boilerplate

php-go

Supported PHP versions: 7.x Build Status

php-go allows to call Go code from PHP, with minimal code boilerplate.

Goals:

  • Allow to export Go functions and Go constants from Go to PHP
  • Be reliable and always safe
  • Deploy Go code without re-building the PHP extension

TODO:

  • Support exporting functions
  • Support all scalar types in arguments and return values
  • Support exporting constants
  • Support slices, maps (copying)
  • Support objects (proxying)

Install

You can download this package using "go get". When using "go get", you'll have to set your $GOPATH first. Then you can run:

go get github.com/arnaud-lb/php-go

When this is finished, change directories to the included "ext" folder:

cd $GOPATH/src/github.com/arnaud-lb/php-go/ext

Then configure and make the binary:

phpize && ./configure && make && sudo make install

Then add extension=phpgo.so to your php.ini, or call php with -dextension=phpgo.so

Note: php-go supports PHP 7 (non-ZTS). For PHP 5, use the php5 branch.

Usage

Exporting Go functions

package main

import (
  "strings"
  "github.com/arnaud-lb/php-go/php-go"
)

// call php.Export() for its side effects
var _ = php.Export("example", map[string]interface{}{
  "toUpper": strings.ToUpper,
  "takeOverTheWorld": TakeOverTheWorld,
})

func TakeOverTheWorld() {
}

func main() {
}

The module can then be compiled as a shared library using -buildmode c-shared:

go build -o example.so -buildmode c-shared .

Note: Go requires that the module be a main package with a main function in this mode.

Using the module in PHP

// Create a class from the Go module, and return an instance of it
$module = phpgo_load("/path/to/example.so", "example");

// Display the methods defined by the class
ReflectionClass::export($module);

// Call some method
$module->toUpper("foo");

More Repositories

1

php-rdkafka

Production-ready, stable Kafka client for PHP
C
1,968
star
2

php-memory-profiler

Memory profiler for PHP. Helps finding memory leaks in PHP scripts.
C
773
star
3

MtHaml

Multi target HAML (HAML for PHP, Twig, <your language here>)
PHP
363
star
4

vim-php-namespace

PHP namespace support for VIM. Types "use" statements for you
Vim Script
252
star
5

php-inotify

Inotify bindings for PHP 5, 7, and next
C
39
star
6

MtHamlBundle

Symfony2 HAML bundle
PHP
38
star
7

imagesize.js

Get the size of an image without reading or downloading it entirely
JavaScript
30
star
8

php-sema

A library for semantic analysis of PHP code
PHP
19
star
9

alb-oembed

Simple PHP oEmbed consumer library with discovery support
PHP
16
star
10

Zwig

Twig / Zend Framework adapter
PHP
16
star
11

TwigReflectionBundle

Displays what's in Twig
PHP
15
star
12

goresize

image resizing proxy written in golang
Go
12
star
13

xtrabackup-manager

xtrabackup-manager fork. Original code at https://code.google.com/p/xtrabackup-manager/
PHP
9
star
14

TwigShellBundle

Simple Twig Shell
PHP
8
star
15

Silex-MtHaml

HAML templating for Silex
PHP
8
star
16

fselectmenu

JavaScript
7
star
17

phpketama

Pure-PHP implementation of libketama, a consistent hashing library
PHP
6
star
18

php-rdkafka-doc

PHP
6
star
19

php-inotify-ffi

Pure-PHP inotify binding (FFI-based)
PHP
5
star
20

binsort

Binsort is a tool to sort files of fixed-length binary records
Go
5
star
21

AlbOpenIDServerBundle

OpenID Provider bundle
PHP
5
star
22

php-throttle

php module for throttling file upload speed
C
4
star
23

fdinfo

progress bar for quiet cli tools
C
4
star
24

OpenISETL

Scala/JVM implementation of the ISETL language
Scala
4
star
25

run

`nohup something >/dev/null 2>&1 &`; shortened
C
3
star
26

sfbootstrap

PHP
3
star
27

mediawiki-php-FastStringSearch

Github mirror of PHP extension FastStringSearch - our actual code is hosted with Gerrit (please see https://www.mediawiki.org/wiki/Developer_access for contributing)
C
2
star
28

zf

zf mirror
PHP
1
star
29

iterm-to-neovim

Converts Iterm2 color schemes to neovim g:terminal_color_x
Go
1
star
30

jQuery.event.queueHandler

Queues handlers to be ran after the current event's handlers have been ran
JavaScript
1
star
31

graphql-demo

A Symfony application demoing a simple GraphQL API
PHP
1
star