简体   繁体   中英

PHP persistent delayed HTTP connection

I'm writing an app the contacts a PHP script on a server to receive messages. It does this once every few seconds, and the server replies with any new messages (or no messages if there aren't any new messages). The messages are generated by another PHP script and put into a database for the message checker script to check and remove once the app receives the message and acknowledges that it has processed the message.

Is there a way for the app to send just one request, and have the reply sent only when there are new messages (maybe an hour after the app first sent the request), so that the app doesn't waste internet data, and also doesn't have to wait up to a few seconds (or however long I set the request interval to) before receiving the message, and maybe have the reply sent directly from the other script that generates the messages, which would mean that I wouldn't need a database anymore, and maybe even keep the connection open for further messages to be sent without the app having to make another request.

Simple Answer: yes, this technique is called websockets, you have a stable connection over which you can also push instead of just poll (like ajax)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM