go-php
go-php copied to clipboard
can you show more code example?
Your idea is very good, but I still do not really understand and understand your library package, you can introduce it in more detail?
Hi, more documentation is definitely on the roadmap (has been for a while...), but the tests should help a lot with understanding how to operate most of the specific APIs. As far as an introduction goes, does this work?
This package allows for embedding PHP in Go applications, calling code and sharing data between implementations efficiently. For instance, you can:
- Use most types of Go variables in PHP as their equivalent types (
int
tointeger
,float
todouble
,struct
tostdClass
,slice
toarray
, etc), as well as return PHP variables back into Go.- Use Go method receivers (i.e. custom types with attached functions) as PHP classes transparently.
Integration between Go and PHP is done by means of linking against the PHP interpreter, which leads to minimal overhead in translation between representations.
It also allows for progessively replacing parts of the application stack with Go, for instance, instead of deploying a standard Apache/NGINX and PHP-FPM stack, you can use this package to handle incoming traffic using Go's built in HTTP server, and call through to PHP as needed.
Having
go-php
act as an intermediary makes it possible to transparently extract and re-build performance-sensitive functionality in Go, without having to refactor other parts of the application.
One thing it might be worth mentioning is recommended ways on how to install PHP on various platforms so it can be compiled, for starters maybe the following:
- MacOS
- Windows 10
- Ubuntu
- Docker builds (I can see the Docker files already exist)
Indeed, though it's possible to side-step the issue by using the Docker images provided and using those as the build environment. Distributing static libraries built against static PHP builds may also be useful, but their use might be a bit more narrow, depending on which modules we include.
I'll expand on the documentation with step-by-step instructions (though my ability to do so for MacOS or Windows is diminished).