I like PHP. It's not overly complex to achieve what you want, you can write straight up HTML inside it, and I suppose I'm just used to it. I also like Go, having just discovered it while looking for something to write the back-end of a web app in that wasn't Node.js (can't abide callbacks everywhere).

I would like to be able to do most page generation in PHP because it's just what I'm comfortable doing for page generation, but I want the heavy lifting at the back to be done by Go. The back-end 'engine' needs to be able to do things like user-scheduled jobs to start with, but later extending to a web service endpoint and more, something I'd feel more comfortable doing in a compiled, statically typed language such as Go.

The only way I can think of allowing this to work is having all the PHP on an HTTP server and making REST or SOAP calls to the engine written in Go. Is this the only way to allow interoperability between the two languages or is there some other way?

  • 1
    Does go have it's own templating language? Even when I used to write PHP, we used a templating language like smarty instead of PHP directly. It's a good chance to learn something new imo.
    – tom
    Oct 9, 2014 at 10:22
  • 1
    It looks to have a built in one: hoisie.com/2012/03/17/the-builtin-go-template-language I'll give that a whirl.
    – Adam
    Oct 9, 2014 at 10:32

2 Answers 2


Sockets are a perfectly acceptable way to do language interop. The protocol you use to pass the messages between two different processes doesn't really matter much if you only plan to expose one of them to the rest of the world. If the long term plan is to make them both available then going with a standard protocol like HTTP with JSON is the right solution.

FFI (foreign function interface) is also a potential solution but I don't really know much about PHP and its FFI support to say whether this is better or worse than going with plain sockets.


PHP is a server-side programming language. If you want to communicate with other applications, you need to implement webservices in your Go and have PHP doing requests to those webservices. There are various ways already implemented in most of the established frameworks (Laravel, Phalcon, Symfony, Zend, CodeIgniter, CakePHP and so on - the list really is huge). The way to achieve this without a PHP framework behind your project, is via cURL calls.

However, the workflow of this is as follows: the user will have to initiate an action by doing a request to your PHP server-side component, which in turn will do a cURL request to the Go backend and afterwards serve the appropriate response back to the user. It's basically the same thing as the user doing a request directly to the Go backend, except you can do intermediary processing in the PHP component, on your requests to and responses from the Go backend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.