WebSocket
In websockets the process is very similar to normal HTTP, but the difference is that we do not close the connection and we do not need to request the server again to know when something new exists, the event inside ws
receives signals or data directly from the server .
If you write a basic websocket it will probably be synchronous, if the user
A
sends something too long, the process will probably be "stopped" until finished, but at the time of sending the other users to the long message from the user
A
all will probably receive at the same time.
However when reading about ratchetphp/Ratchet
, more specifically this message:
Also in the link indicated in the github comment, there is the option to use "children process":
-
link )
And there in the repository is the following description:
Asynchronous ChildProcess (en: Asynchronous child process)
Example usage:
$loop = React\EventLoop\Factory::create();
$process = new React\ChildProcess\Process('echo foo');
$process->on('exit', function($exitCode, $termSignal) {
// ...
});
$loop->addTimer(0.001, function($timer) use ($process) {
$process->start($timer->getLoop());
$process->stdout->on('data', function($output) {
// ...
});
});
$loop->run();
In short: So how websockets work in PHP will depend on how the code was written, reactphp
is already asynchronous and still supports child-process
, so using the library well, the user B
will not have to wait for the A
user to be able to interact with the websocket.
A socket within php works much like a normal socket, we usually use fsockopen
or stream
, or even other libraries as curl
. >
PHP is written in C ++, so it will probably depend on what php extension you are referring to. But the basics is that it connects through a socket, it will depend on you as a developer to define, for example to make an HTTP request it is necessary to make a request for TCP.
HTTP Servers
But if what you want to understand is how client request management works for a "normal" server that uses PHP (production server), I have to tell you that it is not the php that manages this, a href="https://httpd.apache.org"> Apache or Nginx or lightTPD , which are HTTP servers.
- Note that PHP is the backend of the HTTP server, as opposed to PHP, you can use Python or other interpreters / compilers, so PHP responds to the HTTP server and this same server responds to the client (user's browser).
Both Apache and other servers divide requests by childs
(which are a kind of "thread"), in apache the process is synchronous but still has several childs which allows several people to access without having to wait the other. You can set limits on Apache itself, remember the larger the limit the more memory you will need.
The Ngnix and lightTPD servers are said to be asynchronous, which probably divides the childs
differently and allows a larger number of users to access at the same time, but still use these childs
. >
The childs are like threads or subprocesses, connections are likely to be split between these subprocesses and returned later.
Each type of server has its own way of managing the connections and returning the response of requests, this can also vary with the type of server, such as a server that uses a Linux kernel or a Windows-based server.
But in the basics the user B
does not have to wait for the A
to finish its execution.