Hi everyone,
If any of you have done PHP scripting with sockets, you've probably noticed that if your script is terminated unexpectedly and the socket is not closed, you get this error next time you start the script up:
PHP Warning: socket_bind() unable to bind address [98]: Address already in use in ....
Has anyone figured out a way around such errors? I am reusing my sockets and they're set in nonblocking mode - but I always get this error. It's very strange.
You see, my script calls shell_exec and executes a bash script which loads an application. For some reason, this command hangs. In the event the PHP script which initially called the bash script (the socket server) is terminated, the socket remains open and bound to the IP and Port initially set. When the script is booted back up, it cannot bind to that address until I kill the application proccesses (which were created through the bash script, which was called from the PHP script).
So, basically, the question is, is there anyway - either through PHP or doing something directly in the OS to automatically unbind these connections if my PHP script is found to not be running?