Business process is like this, we PHP server with the socket connection to the other server, the other server will send a message to our PHP server, so we need to read,read PHP always need to send a heartbeat every three minutes to each other, when PHP has been read, When the other party did not send the message, PHP has been waiting, how to ensure that every three minutes to send a heartbeat?
Reply content:
Business process is like this, we PHP server with the socket connection to the other server, the other server will send a message to our PHP server, so we need to read,read PHP always need to send a heartbeat every three minutes to each other, when PHP has been read, When the other party did not send the message, PHP has been waiting, how to ensure that every three minutes to send a heartbeat?
Generally this does not use PHP to do very well.
Delay 3 minutes sleep (3)
Always execute script set_time_limit (0)
Disconnect from client continue execution Ignore_user_abort (0)
You can consider using Swoole
When you read, you have to give it a heartbeat, do it with PHP-CLI.
Swoole can easily take care of your needs