Geesu
Geesu

Reputation: 6008

Best method for a PHP script to communicate with an application?

I'm currently writing a c++ application for a linux server which basically handles requests (I haven't coded the part handling the requests yet, as I'm not sure of the best method).

Basically I have a PHP page that when fired (client hits the page) needs to communicate with the above mentioned application.

Now I can't fire off this application each time it's needed, as it's a rather complex application that needs to load data before it can do any processing (so it should just stay loaded forever as a daemon).

How would you suggest I have the PHP page make requests to the application? Should I just use socket programming with TCP/IP?

Thanks in advance!

Upvotes: 1

Views: 2086

Answers (3)

SirDarius
SirDarius

Reputation: 42899

ZeroMQ is another project that can help you building a communication layer between your PHP code and a C++ daemon.

There are bindings for C++, PHP, and many other languages.

Upvotes: 2

Carsten
Carsten

Reputation: 18446

You could of course try and use raw sockets, but you don't need to. There are products that help you with what you want.

I suggest you take a look at Apache Thrift. You can easily define what functions your C++ part offers and convert it into a daemon that waits for your requests from PHP. And of course there's a PHP library which you can use to make these requests.

Upvotes: 2

Khôi
Khôi

Reputation: 2143

If you're familiar with unix sockets, you might use unix domain sockets too:

http://www.php.net/manual/en/transports.unix.php

Upvotes: 0

Related Questions