http server in php

半世苍凉 提交于 2019-11-27 03:37:40

问题


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. How can I solve that problem ???


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/5937457/http-server-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!