http server in php
Asked Answered
E

5

6

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 ???

Edea answered 9/5, 2011 at 13:20 Comment(3)
Be sure to watch out for execution timeouts. Also, as far as I know it lacks threads that you see in most web servers. Another language would probably be a better choice if possible.Tempura
You can look into Nanoserv nanoserv.si.kz or PEARs Net_Server pear.php.net/package/Net_ServerSimla
What webserver you are using? or you want to create your own web server? wouldn't it be reinventing the wheel?Punctilious
A
4

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

Allanite answered 9/5, 2011 at 13:22 Comment(0)
D
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.

Drainpipe answered 9/5, 2011 at 13:25 Comment(0)
O
1

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.

Overstrain answered 18/5, 2011 at 9:27 Comment(3)
There is nanoweb.si.kz and it did outperform Apache 2.0 on PHP4. While it's not a complete replacement for production settings, can be suitable for some app settings.Simla
I can name at least five different webservers that will outperform Apache 2.0. That doesn't mean it's a good idea to build it all over again.Overstrain
@BerryLangerak u r absolutely right: php is NOT for this - even if u can get php code to open a socket 4 u and listen to it for a whileJus
J
1

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.

Jus answered 6/2, 2013 at 14:39 Comment(0)
S
0

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.

Simla answered 18/5, 2011 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.