I
I
ie2002020-02-27 16:39:57
PHP
ie200, 2020-02-27 16:39:57

How to combine golang with php?

Hello everybody!

Many people are trying to find out if Golang can be combined with PHP and vice versa. But ... there is little information on the Internet, or I'm not looking well. However, lately I've been asking myself this question. And I would like to know the truth.

Let's imagine such a situation. You have implemented MVC in PHP, for example: A system for parsing associative semantic cores. Then you are faced with the problem of data processing. The database sends a response in 0.003 seconds. But... due to data processing, loading a user page is some 14 to 20 seconds. I understand this is not acceptable!

Therefore, you resort to using Ajax requests or separating services into Server and User. After that, the loading of the user page is approximately the same numbers, from 10 to 15 seconds.

Forgot to say that the database answers you in about 1 million rows. Which significantly affects the processing of data. Therefore, such a long loading of the user page.

Now let's talk about the division of services into Server and User. You decide to test new unknown sciences. You think that the multi-threaded Golang language will save the whole world. This means that the task of introducing this language into your system appears, which is the usual MVC.

Then the question arises: how exactly to do this and how to implement it?

There is a certain architecture of your project directories that must exist in the ecosystem (strictly):

|- app /
    |- core /
        controller.php
        model.php
        route.php
        view.php
    |- lib /
        |- messages /
            errors.php
        |- security
        |- validation
        database.php
        vendor.php
    init.php

|- build /
    |- controllers 
        home.php
    |- models/
        |- home
            index.php

|- private /
    |- config
        routes.php
    |- database
        name_database.sql

|- public /
    |- api /
        connect.php
    |- docs
    |- res /
        |- src

|- template /
    |- errors /
        404.html
    |- layouts /
        default.html
    |- views /
        |- home /
            index.html

|- web /
    |- css
    |- js
    .htaccess
    index.php
.htaccess


You need to implement Golang in PHP to send database queries, process data, send response to a custom page that is written in PHP. But ... you have difficulty in implementing this idea.

Yes, it can be implemented using websocket. Still, the desire to see this is not in words, but in deeds!

Now for the implementation questions:
  1. Could you suggest a way to implement Golang in PHP?
  2. Could you give an example of this implementation?
  3. What other alternatives can you suggest? For example, combining Vue with PHP.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-02-27
@FanatPHP


loading a custom page is about the same numbers, from 10 to 15 seconds.
the database answers you in about 1 million lines
, the question arises: how exactly to do this and how to implement it?

Two simple steps:
1. Tear off the hands of the one who wrote all this, and put them in him where they grow from.
2. Hire a PHP junior who has already mastered the basic SQL syntax and can query the database for the required number of rows.
PS.
What other alternatives can you suggest? For example, combining Vue with PHP.

Take a close look at whoever submits such ideas to solve this problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question