Note that there are some explanatory texts on larger screens.

plurals
  1. POEventMachine and Twitter streaming API
    primarykey
    data
    text
    <p>I am running an EventMachine process using the Twitter streaming API. I always have an issue if the content of the stream is not frequently.</p> <p>Here is the minimal version of the script:</p> <pre><code>require 'rubygems' require 'eventmachine' require 'em-http' require 'json' usage = "#{$0} &lt;user&gt; &lt;password&gt; &lt;track&gt;" abort usage unless user = ARGV.shift abort usage unless password = ARGV.shift abort usage unless keywords= ARGV.shift def startIt(user,password,keywords) EventMachine.run do http = EventMachine::HttpRequest.new("https://stream.twitter.com/1/statuses/filter.json",{:port=&gt;443}).post( :head =&gt;{ 'Authorization' =&gt; [ user, password ] } , :body =&gt;{"track"=&gt;keywords}, :keepalive=&gt;true, :timeout=&gt;-1) buffer = "" http.stream do |chunk| buffer += chunk while line = buffer.slice!(/.+\r?\n/) if line.length&gt;5 tweet=JSON.parse(line) puts Time.new.to_s+"#{tweet['user']['screen_name']}: #{tweet['text']}" end end end http.errback { puts Time.new.to_s+"Error: " puts http.error } end rescue =&gt; error puts "error rescue "+error.to_s end while true startIt user,password,keywords end </code></pre> <p>If I search for a keyword like "iphone", everything works well If I search for a less frequently used keyword, my stream keeps to be closed very rapidely , around 20 sec after the last message. Note: that http.error is always empty, so it's very hard to understand while the stream is closed... On the other end, the nerly similar php version is not closed, so seems probably in issue with eventmachine/http-em but I dont' understand which one... </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload