如何从PHP发送通知到C#服务?

I have a Windows service written in C# that handles processing of digital documents, and a web application written in PHP. I need to be able to notify the C# service that new documents are ready for processing.

Currently, the C# service is reading the MySQL database every 10 seconds to see if there are new tasks to be performed. This creates a 10 second lag in the responsiveness of the web application. I'd like to be able to trigger the C# service immediately when the document is ready.

I'm looking for an answer that will allow PHP to notify the C# service without any delay.

Here are some possible ideas that I've had;

  • Use a shared memory object between PHP and C#, and have a thread in C# wait for that object to be signaled. Is this possible with PHP?
  • PHP connects to C# using a socket on localhost, sends a nak and disconnects. This seems inefficient to me.
  • Configure MySQL to use an in-memory table, and have the C# service query the table every second.
  • Is it difficult to create some kind of web service in C# that uses XML or SOAP, and would there be any lag (+1 second) in calling that service via PHP?

That's all I can think of. Maybe there is some kind of standard way this should be done, and I'm just not aware of it.

It'd be pretty trivial to make a REST facade in WCF that triggers your c# service on a POST against /. Security can be layered on depending on the nature of your deployment.

http://msdn.microsoft.com/en-us/library/bb412178.aspx

I'm going to go ahead and try to answer this.

In your service, add an OnCustomCommand handler as described in this question to trigger the service work: How to send a custom command to a .NET windows Service from .NET code?

Create a separate C# application that simply sends the command to your service and call that from PHP via the exec() function.

You could self-host an ASP.NET WebAPI in your service