deuill / go-php

PHP bindings for the Go programming language (Golang)
MIT License
930 stars 105 forks source link

can you show more code example? #52

Open MariaWf opened 6 years ago

MariaWf commented 6 years ago

Your idea is very good, but I still do not really understand and understand your library package, you can introduce it in more detail?

deuill commented 6 years ago

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 to integer, float to double, struct to stdClass, slice to array, 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.

adamlc commented 6 years ago

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:

deuill commented 6 years ago

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).