Krisa Krisa - 1 month ago 18
reST (reStructuredText) Question

PHP - cross-aplication comunication

I have two PHP aplications on my server. One of them has RESTAPI which I would like to consume and render in the second aplication. What is better way then curling the API? Can I somehow ask php-fpm for the data directly or something like that?

Doing curl and making request through the webserver seems wrong.

All this happens on single server - I know it probably doesnt scale well but its small project.

Thank you!

Answer

why use REST if you can access the functions directly?

If everything is on the same server then there is no need for some REST, since it makes a somewhat pointless run through the webserver. But if it is already there and you don't care about the overhead (if there's not much traffic going on then it would make sense), then use file_get_contents instead of curl, it is easier to use, but I doubt it is faster/slower; both are right.

You could also use a second webserver (a second virtualhost) on a different port for internal use. That way things are nicely separated.

(If everything is on different servers, but a local network, then using sockets would be fastest. )

Comments