如何在 Linux 上从 PHP 通知 Windows .net 服务?
我正在 Windows 上用 C# 编写一个服务,该服务应该由在 Linux 上运行的 PHP 驱动的 Web 前端触发。
两个进程共享相同的 SQL Server 2005 数据库。
atm 没有可用的消息传递中间件。
PHP 进程在 SQL Server 表中插入一行。 Windows 进程应该读取此条目并对其进行处理。
我没有 PHP 经验,那么您建议如何通知 Windows 进程?
I'm writing a service in C# on Windows which should be triggert by an PHP driven web frontend, which runs on Linux.
Both processes share the same SQL Server 2005 database.
There is no messaging middleware available atm.
The PHP process inserts an row in a SQL Server table. The Windows process should read this entry and process it.
I have no experience in PHP, so what would you suggest to notify the Windows process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我看到至少有两种方法可以完成该任务:
I see at least 2 ways to accomplish that task:
查看 .Net 中的 SqlDependency。它允许您在 SQL 服务器上设置触发器。 MSDN 中有一个示例应用程序。
Check out SqlDependency in .Net. It allows you to set a trigger on the SQL server. There's a sample app at MSDN.
让服务定期轮询 PHP 进程写入的数据库表。我做了类似的事情,表中有一列一开始为空,然后在处理该行后由 Windows 服务设置。该服务仅要求该字段中包含空值的第一行,执行该操作,然后更新该字段,然后重复。这样,如果系统或应用程序崩溃,那么在重新启动时,它会继续处理未处理的行。请记住将事务中的读取和写入括起来。
Have the service periodically poll the database table that the PHP process writes to. 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. 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.