Server-Sent Events Polling causing long delays

后端 未结 1 941
忘掉有多难
忘掉有多难 2020-12-07 04:21

I have a connector that will call a RESP API using cURL and PHP.

I need to call one method every second to check for new messages and then process them. I used the f

相关标签:
1条回答
  • 2020-12-07 05:16

    Everything looks robust, so I'm going to take a guess that you are being hit by session locking. PHP sessions lock the session file, such that only one PHP script can use the session at a time; when you think about it, this is a great idea!

    The problem with sessions and SSE is that the SSE PHP process runs forever, and therefore it locks the session forever. If any other PHP script tries to run with the same session, it will block (at the session_start() call, I believe).

    This looks like a good article on the subject; the advice is to call session_write_close() once you know longer need the session. E.g. if you just need to use the session to check they have previously authorized themselves, then straight after that you call session_write_close(), and other processes will not get blocked.

    0 讨论(0)
提交回复
热议问题