Skip to content Skip to sidebar Skip to footer

Server-Sent Events Polling Causing Long Delays

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 following 2 appr

Solution 1:

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.


Post a Comment for "Server-Sent Events Polling Causing Long Delays"