I'm looking to have a web application spawn a socket server thread in the background. Each PHP session gets its own thread, and there can be any number of threads.
I bind the socket using a port of zero, so that it picks a random open port. My socket server starts correctly, and moves into it's listening loop without issue. The issue I have, however, is that my PHP script that starts the thread using shell_exec()
needs to get a response from the thread indicating which port must be used to communicate. The problem is that if I start the thread and wait for a response, the client script will sit and wait for the server thread to complete, instead of moving on and communicating with it via sockets.
Is there a way for PHP, when run from CLI or shell_exec() to say, "Okay, that's the last of my output, go ahead and continue on."?
My structure is mostly as follows:
Server.php
Start socket listener
Output chosen port
Do { Application Loop }
Client.php
Start Session
If !Session['port'] {
Start Server.php, receive Port //This is where it waits forever
}
Communicate with server thread via Port
I hope this is clear. Please comment if it is not.