I’m going to only chime in on this exactly one time -
Please don’t use PHP to try and persist connections. That’s not what it’s for. PHP is not a stateful language, and is not intended for long running sockets. The amount of hackery you will be out of control.
Use javascript, use web sockets, use actual normal sockets, use any language that’s actually intended to maintain persisted connections.