0

I have been writing applications that use Twitter Streaming API. I am using TheMattHarris OAuth library I found on GIThub. This is how I typically set up my streaming process.

I call the stream.php asynchronously first like so:

xmlhttp.onreadystatechange = function(){
   // end of stream
}
xmlhttp.open("GET", "stream.php?term="+term, true);
xmlhttp.send();

My stream.php looks like this:

$connection = new tmhOAuth(array(
   'consumer_key' => CONSUMER_KEY,
   'consumer_secret' => CONSUMER_SECRET,
   'user_token' => USER_TOKEN,
   'user_secret' => USER_SECRET,
));
$method = "https://stream.twitter.com/1.1/statuses/filter.json";
$connection->streaming_request('POST', $method, array('track'=>$term), 'twitter_callback');
tmhUtilities::pr($connection);

function twitter_callback($data, $length, $metrics) {
   // handle tweet here
}

The problem is that I can't seem to stop this stream. I don't know how long it runs before it runs itself out. Since this is a web application, I can refresh the page and search for a new term, but the old stream still seems to be running.

So I have two questions: how do I stop such streams? And is this the right way to implement a Twitter stream?

1 Answer 1

0

I think xmlhttp.abort() would do the trick. You can see an example of how to do a abort button here:

http://help.dottoro.com/ljomfaxv.php

2
  • But I think this will just stop the readychange events from firing and change the readystate. The streaming, on the other hand, is happening on the PHP side and will not be affected by this
    – Rajagopal
    Jun 1, 2014 at 11:52
  • If there is no stream connecting to your PHP script, it will just cease to execute. Though I am not totally sure, I thing abort(); is the right way to go...
    – Diederik
    Jun 1, 2014 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.