Http server in php

I want to create an HTTP socket connection for a server in php for multiple clients. How can I do it? I need a resource.

At first I tried to create a server in java. I am creating a server in java. And trying to contact the Android app. But the server cannot find any client. But when I create a client in java. He worked. How can I solve this problem?

+6
source share
5 answers

Personally, I think that this would be a good idea, as it was already mentioned that it lacks Threading, and Socket (imo) support is not really adaptable.

The only plus side is that you can use fork to deploy another PHP process to handle the client, but you become very complicated.

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

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

+2
source

Are you trying to use PHP for what? Keep in mind, I like PHP and work with it almost every day, but please remember that PHP inside and on its own is based on request and response and is not very suitable for lengthy processes. In the manner of exercises, this may be interesting, but if you are trying to write a web server from scratch using PHP, you may need to reconsider your choice of language.

However, you can create a socket acting as a server and listen for incoming packets. I still think you are reinventing the wheel, though.

+1
source

although I love php and java, I wrote my socket servers in C ++ running under a lamp on ecazon ec2 cloud server. it is very, very simple to code and debug and safe, and you can almost simply copy / paste the examples.

ultimately, I will probably develop a Java solution because of portability and scalability, but the initial effort to work with a C ++ solution is much less than implementing a Java solution ...

The first thing you need to find out (find out) is whether your server allows you to open user ports. amazon ec2 does at the moment (feb13), can be used for free for 12 months.

So this is for you if you are in a hurry:

This set of examples contains everything you need as soon as possible.

+1
source

Judging by the name of the question (the rest only makes it more confusing), you can use an existing package, for example http://pear.php.net/package/HTTP_Server to implement a web server in PHP. It already contains socket code to accept client connections and more.

So what do I need to do to find the server from another client

Search is too broad a topic. Depends on your actual setup. There are several discovery protocols on the local network. Otherwise, you should simply rely on a fixed machine name and port number for your created server. You can connect to it, for example. http://localhost:8007/ or whatever you predetermined.

0
source

Source: https://habr.com/ru/post/887618/


All Articles