Here is my backend layout: a request is put through a socket.io socket that communicates to php_script
. PHP returns to socket.io that dispatches yet another request to php_script2
and answers the frontend regarding the original request (to php_script
). php_script2
sleeps in its algorithm and occasionally sends data back to the socket layer. The problem appears when the same user that issued the original request tries to interact with the socket while php_script2
is running. (The frontend freezes upon trying to send new info to socket.io). This is:
1 - user sends input
2 - socket.io received input
3 - socket.io sends input to php as an http_request with the following options:
var options = {
host : 'localhost',
path : path,
method : method_type,
rejectUnauthorized: false,
requestCert: true,
agent: false,
headers : headers
};
4 - PHP (php_script) processes request and sends feedback to socket layer
5 - Socket layer receives feedback in the functionToPhp, interacts with the user socket socket.emit("success")
and issues a new php request to php_script2
with the same options as before
6 - Frontend confirms reception of the data packet (php_script2
is running) and if the user tries to send new information to the socket that requires new interaction with php, the frontend element freezes (in this case a textarea, it is made up to freeze but unfreeze as soon as "success" is received from the socket.io). It unfreezes only as soon as the php_script2
ends all its process including sleep while it should unfreeze right away.
I did it this way (nodejs->php->nodejs=>php->nodejs) precisely because I didn't want the original request from the user to nodejs to be "stuck", so, right in the second layer of nodejs (before the =>
) I output "success" to the user and issue a new request from nodejs to php as to imitate threading
and go async. Unfortunately this isn't happening and the user is still waiting for the callback after php_script2
has ended. Why exactly is this working? I understand how a server works but I'm not really understanding how can the request remain tied if it is issued again in a localhost perspective. I hope I was clear, tyvm for your help...