开发者

php socket programming,Pros and cons and Approach

开发者 https://www.devze.com 2023-02-09 12:34 出处:网络
I am working on a task where it is required to distribute live data (being fetched from some other server) to client using sockets. We user drupal as a framework and thus my choice of PHP.

I am working on a task where it is required to distribute live data (being fetched from some other server) to client using sockets. We user drupal as a framework and thus my choice of PHP.

1)I want to know the major factors that should be taken into consideration while developing this server.Like security,authentication,load etc and how should i approach this.Is there any blog/article that could be of help.

2)Is there a better choice than PHP for this?

3)ALSO is there any drupal module that coul开发者_如何转开发d assist me in this.


  1. I can think about one issue when you are talking about several servers connecting to you, you may want to conceder a nonblock mode.
    Because when you are working with blocking mod, each server can connect at the time, meaning that there will be delay delivering the message. http://il2.php.net/manual/en/function.socket-set-nonblock.php

  2. I think java would be better choise, multi thread may help here.

  3. from my point of view, this is something that you need to develop your self, socket programming needs a lot of attention.


Drupal is a Web CMS, it can be used as framework for advanced web features or light to medium web application that fits well in the traditional HTTP request paradigm. IMHO, distributing live data from multiple servers to client using sockets doesn't fit with the base assumption behind Drupal's design.

PHP can be used to write socket server. It used to be un-common, but it is becoming more and more available. ReactPHP is a non-blocking I/O library/framework suited for socket programing. Racthet is a websocket server in PHP using ReactPHP.

In any case, this would ne nothing like developing a web application with RoR, Drupal, Django, Symfony, etc.

If integration with a Drupal website is required, the Service module is a nice solution to provides a REST or XML-RPC API. Or course, direct access to Drupal's MySQL database is also an option but will probably require more knowledge of the used Drupal modules since you will have to replicate their behaviors and understand how they manage their data (for instance, how a particular CCK field is stored in your database).

Note: Previous version of this answer included reference to the following solutions in other languages: Twisted (Python), EventMachine (Ruby) and Node.js (JavaScript). These are all valid solutions when PHP is not required. Previous version of the answer also referenced phpsocketdaemon, but nowadays ReactPHP is a more clean and robust solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消