简体   繁体   English

PHP套接字客户端-C#套接字服务器

[英]Php socket client - C# socket server

I'm developing a system that consists of a Php web server and a C# program. 我正在开发一个由Php Web服务器和C#程序组成的系统。 They both run on the same host. 它们都在同一主机上运行。 The web server receives data from clients (mobiles) then updates to a database and sometimes it should notify the C# program. Web服务器从客户端(移动设备)接收数据,然后更新到数据库,有时应通知C#程序。 To do this, I open a socket client on Php side then connect to a socket server on C# program side, like this: 为此,我在Php端打开一个套接字客户端,然后连接到C#程序端的套接字服务器,如下所示:

(Php web server side) (Php Web服务器端)

1) process HTTP Request from clients

2) update data to database

3) if need to notify C# program (depending on received data)
    3.1) open a socket client (localhost, 8888)
    3.2) send data
    3.3) close socket

Until now, our system works quite well with small number of clients (for testing) but I'm not sure in case of large amount of clients. 到目前为止,我们的系统在少数客户端(用于测试)上运行良好,但是对于大量客户端,我不确定。

Anyone can give me some comments to increase the performance! 任何人都可以给我一些评论以提高性能!

Sockets are relatively very fast; 套接字相对来说非常快。 related to using say message Q. Socket per se would not choke; 与使用说消息Q有关。套接字本身不会阻塞; your single C# program should be able to cope up with the load; 您的单个C#程序应该能够应付负载; else the messages would continue to pile up and eventually socket send calls would start backing up. 否则消息将继续堆积,最终套接字发送调用将开始备份。

Message Q systems are systems designed to do what you are trying to do here - they provide a middleware that allows sending and receiving messages. Message Q系统是设计用来执行您在此试图做的事情的系统-它们提供了一种中间件,该中间件允许发送和接收消息。 They offer things like recovery, guaranteed deliver, allow you to scale out (by using say multiple receiver C# programs), etc. You can look at them. 它们提供恢复,保证交付,允许您扩展(通过使用多个接收器C#程序)等功能,您可以查看它们。

If you are too worried about sockets performance, you could use some sort of interprocess communication, details of which are OS dependent. 如果您太担心套接字的性能,则可以使用某种进程间通信,其详细信息取决于操作系统。 Things like shared memory, pipes etc. Usually all of them, including sockets, are fast enough that you would not notice much difference in normal routine use. 诸如共享内存,管道等之类的东西。通常所有这些东西,包括套接字,都足够快,以至于您在正常的日常使用中不会注意到太多差异。 The difference would be apparent only at very high rates . 这种差异只有在非常高的速率下才会显现出来。

You could also look at things like in memory databases. 您还可以查看内存数据库中的内容。 PHP writes it into in memory DB; PHP将其写入内存数据库; C# program reads off the in memory DB C#程序读取内存DB

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

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