A
A
Anastasia2017-11-09 23:50:19
PHP
Anastasia, 2017-11-09 23:50:19

How to create a library on go and use via php?

There is a site in php, the possibility of using functions written in go is of interest.
something like this:
1) golang has a function

func Hello(name string) (string){
    return "hello "+name
}

2) I want to use in the code on the site
inlude ("some-bridge-file");

echo hello("world");

3) Alternatively, maybe go can somehow be compiled into js and then called right on the page?
4) I know that it can be compiled as a dll (I couldn’t find a working example, I didn’t understand English very well, I didn’t understand compilation), but in php it seems like it’s really possible to call a function from a dll through COM. If anyone has an example of such a connection would be grateful!
PS do not suggest rewriting the entire server on go (I tried it, it's interesting, but! I want to expand the functionality of the existing site, but it takes a long time to write it in php (I don't know php very well), but go turned out to be closer to me ;-)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RidgeA, 2017-11-10
@Tauc2005

I would suggest that the part that needs to be written in go be made a separate service, where to access via http api.
options with compilation to dll, transpilation to js and extension for php seem to me not very successful.

A
Alexander Taratin, 2017-11-10
@Taraflex

You can build go code as a php extension
https://github.com/kitech/php-go

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question