Krisa
Krisa

Reputation: 85

PHP - cross-application communication

I have two PHP applications on my server. One of them has RESTAPI which I would like to consume and render in the second application. 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 doesn't scale well but its small project.

Upvotes: 1

Views: 399

Answers (3)

Alex
Alex

Reputation: 6037

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

Upvotes: 1

I was in the same problem, but i solved it using MySQL to "queue" tasks, and a worker could use any pooling method, or PHP executing a new server side worker. Since the results were stored in the same database, the PHP pages could load the results, or the status anytime.

Upvotes: 0

Okafor T Kosiso
Okafor T Kosiso

Reputation: 308

Doing curl and making request through the webserver seems wrong. - I disagree with that. You can still achieve what you want to achieve using Php CURL, even if it's on the same server.

Upvotes: 0

Related Questions