简体   繁体   English

如何从Linux上的PHP通知Windows .net服务?

[英]How to notify a Windows .net service from PHP on Linux?

I'm writing a service in C# on Windows which should be triggert by an PHP driven web frontend, which runs on Linux. 我正在Windows上用C#编写服务,该服务应由在Linux上运行的PHP驱动的Web前端触发。

Both processes share the same SQL Server 2005 database. 这两个进程共享相同的SQL Server 2005数据库。

There is no messaging middleware available atm. 没有atm可用的消息传递中间件。

The PHP process inserts an row in a SQL Server table. PHP进程在SQL Server表中插入一行。 The Windows process should read this entry and process it. Windows进程应读取并处理该条目。

I have no experience in PHP, so what would you suggest to notify the Windows process? 我没有PHP经验,那么您建议通知Windows进程什么?

I see at least 2 ways to accomplish that task: 我看到至少两种方法可以完成该任务:

  1. Host in process WCF service in windows service and call it from PHP . 在Windows服务中托管进程WCF服务 ,并从PHP调用它
  2. Write events in the database from PHP and subscribe on them using SqlDependency . 从PHP将事件写入数据库,然后使用SqlDependency对其进行订阅。

Check out SqlDependency in .Net. 在.Net中检出SqlDependency It allows you to set a trigger on the SQL server. 它允许您在SQL Server上设置触发器。 There's a sample app at MSDN . MSDN上有一个示例应用程序。

Have the service periodically poll the database table that the PHP process writes to. 让服务定期轮询PHP进程写入的数据库表。 I do something similar and have a column in the table that is null to begin with, and then is set by the Windows service once the row is processed. 我做类似的事情,并在表中有一列以null开头,然后在处理完该行后由Windows服务设置。 The service merely asks for the first row that contains a null in this field, does it's thing, then updates the field, and then repeats. 该服务仅要求在该字段中包含空值的第一行,这样做,然后更新该字段,然后重复。 This way if the system or app crashes then when restarted it continues with that unprocessed row. 这样,如果系统或应用程序崩溃,则在重新启动时它将继续处理该未处理的行。 Remember to bracket your reads and writes in transactions. 请记住在交易中括住您的读写。

I'm answering my question here, because in the end we notified the app via plain old sockets. 我在这里回答我的问题,因为最后我们通过普通的旧套接字通知了该应用程序。

So a valid answer to my question is use sockets. 因此,对我的问题的有效答案是使用套接字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM