开发者

http server in php

开发者 https://www.devze.com 2023-03-03 18:24 出处:网络
I want to create http socket connection for server in php for multiple client . how can I do that ? I need some resource .

I want to create http socket connection for server in php for multiple client . how can I do that ? I need some resource .

First I was trying to create server in java .I create a server in java . And trying to reach from android application .But server can't find any client.But when I create client in java .It was working. H开发者_StackOverflow中文版ow can I solve that problem ???


Take a look at this article:

Writing Socket Servers in PHP by Zend

Also give a try with Google:

http://www.google.com/search?aq=0&oq=php+socket+server+mul&sourceid=chrome&ie=UTF-8&q=php+socket+server+multiple+clients


Personally I think this would be a pretty bad idea, as already mentioned it lacks Threading and it's Socket support (imo) isn't really that adaptable.

The only plus side is that you can use fork to fork off another PHP process to handle a client, but you're getting very complex.

Another language would be much more suited for this type of development.

Note that even if you did do this in PHP, you'd probably have to rely on external services anyway, and possibly even end up writing at least some code in another language anyway.


You're trying to use PHP to do what? Mind you, I like PHP and work with it almost every day, but please do remember PHP in and on itself is based on request and response, and not very suitable for long running processes. In a manner of exercise, it might be interesting, but if you're trying to write a webserver from scratch using PHP, you might want to reconsider your choice of language.

That said, you can create a socket acting as a server, and listen to incoming packets. I do still think you're reinventing the wheel though.


though i love php and java, i wrote my socket servers in c++ running under lamp in an amazon ec2 cloud server. it is very, very simple to code and debug and safe and you can practically just copy/paste examples.

in the long run, i will probably develop a java solution because of portability and scalability, but the initial effort to get a c++ solution working is just so much less than implementing a java solution...

the first thing you must ascertain (find out) is whether your server allows you to open custom ports. amazon ec2 does and at this point in time (feb13), can be used for free for 12 months.

so, this is for you if you are in a hurry:

this here set of examples has all that you need to be up and running in no time.


Judging from the question title (the rest only makes it more confusing) you could use an existing package like http://pear.php.net/package/HTTP_Server to implement a webserver in PHP. It already contains all the socket code to accept client connections and stuff.

So what i have to do to find the server from different client

"Finding" is too broad a topic. Depends on your actual setting. On a LAN there are some protocols for discoverability. Otherwise you should just rely on a fixed machine name and port number for your instantiated server. You can connect to it as e.g. http://localhost:8007/ or whatever you've predefined.

0

精彩评论

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

关注公众号