views:

19

answers:

1

For a recent project, I have a PHP script running as a CLI-based daemon. This daemon will be responsible for monitoring/controlling independent worker processes.

Periodically, users will issue requests to manage workers through a PHP web front-end (CLI daemon and front-end code are on the same physical server). The front-end will need to make method calls to the daemon.

I'm confused about how to handle these "remote" method calls. I thought that using a RPC protocol such as JSON-RPC over a standard UNIX or TCP socket would be the way to go, but every implementation of JSON-RPC, XML-RPC, SOAP, etc. for PHP seems to be tightly coupled to HTTP. Since I'm not communicating over the web, HTTP is completely unnecessary.

So, two questions:

  • Why are most of the PHP RPC packages coupled to HTTP?
  • What is the best way to handle method calls as described above?
+1  A: 

Why are most of the PHP RPC packages coupled to HTTP?

This is easy. PHP is tailored for the web. It's rarer to write CLI applications in PHP.

Why are most of the PHP RPC packages coupled to HTTP?

It's more common to have PHP perform RPC on programs running in another language, such as Java, and there are good options there.

For a CLI PHP program, I'm not aware of any out-of-the-box solution. But it should be possible to implement a custom solution with UNIX sockets. See the sockets extension. Note that the nonexistence of multi-threading support in PHP may make this a bit more difficult (to handle multiple connections you'll have to fork or implement your own single-thread scheduler...)

Artefacto