jdolitsky / AppDotNetPHP

PHP library for the App.net Stream API
34 stars 19 forks source link

Stream stops providing data after ADN server responds with keep-alive #42

Closed mootymoots closed 11 years ago

mootymoots commented 11 years ago

I'm opening a stream using the ConsumeStream functions, however as soon as it goes 'quiet', i.e. no data is coming through, ADN servers respond every 60 seconds with:

HTTP/1.1 200 OKServer: nginx/1.2.6Date: Mon, 11 Mar 2013 21:29:27 GMTContent-Type: text/html; charset=UTF-8Transfer-Encoding: chunkedConnection: keep-alive

As soon as the class receives this, no new data will come through. I can see ADN objects coming through previous to this message, and can post them myself, but they instantly stop as soon as the keep-alive arrives.

How can we fix this issue?

mootymoots commented 11 years ago

I see that actually, the issue is the class is reconnecting. In processStream() it has:

if (time()-$this->_lastStreamActivity>=30) { $this->reconnectStream(); }

And then reconnectStream() and closeStream() are called. Followed by httpStream() and httpStreamReceive() which seems to re-establish the stream. This is when I get the aforementioned keep-alive message, and now no data comes down through the stream and seems to be the source of the problem.

neuroscr commented 11 years ago

I would check your filters.

neuroscr commented 11 years ago

Saw the conversation on the Dev Channel. You have a low speed stream, so to make sure the TCP socket stays open, we reconnect after 30secs of idleness to make sure, we're getting updates. In your case upping that value would seem to make sense but just don't make it too high, otherwise you won't know when you're disconnected.

mootymoots commented 11 years ago

Thanks, understood - but why does the reconnect stop working? Isn't that the point of reconnecting :)

jdolitsky commented 11 years ago

@mootymoots sorry for the delay. @neuroscr wrote the stream code, so he would know best in this situation

neuroscr commented 11 years ago

We worked it out in dev channel / PM and I pushed another fix. Increased the reconnect from 30 secs to 5 minutes (plus 30 sec buffer) to make ADN's current keepalive settings.

I think the original 30 sec reconnect bug may have go away with the other fixes, I pushed.