Greg,

Please see the following code for a working example fo how to do the
Streaming API in PHP.  Not sure if it is the best way to do it, but it works
for us, and we use the Streaming API for a lot of data.

http://groups.google.com/group/twitter-development-talk/msg/761eb0b23872d430?hl=en

If you have any questions, please let me know.

-Joel

On Sat, Sep 19, 2009 at 11:48 AM, Chad Etzel <jazzyc...@gmail.com> wrote:

>
> Hi Greg,
>
> A couple of questions:
>
> Are you running this is a browser? It will be much easier to test if
> you can run the script from a console instead. There are all sorts of
> output buffering issues to deal with in a browser.
>
> Even if you are receiving any data from the stream, the way your code
> is setup you won't ever see it:
>
>   $new_data = json_decode($data);
>
>       foreach($status as $new_data)
>       {
>               var_dump($status);
>               echo "<hr>";
>       }
>
> Your foreach syntax is reversed, perhaps? The $new_data variable will
> be blank, but even worse since $status isn't set, the foreach loop
> won't run.
>
> Instead you should try something like:
> $new_data = json_decode($data);
> echo $data;
> var_dump($new_data
> echo "<hr>";
>
> That way at least you can determine if you are getting any data from
> the stream at all.
>
> -Chad
>
> On Sat, Sep 19, 2009 at 10:31 AM, Greg <gregory.av...@gmail.com> wrote:
> >
> > I'm trying to implement Streaming API on my Twitter application to
> > enhance the stabilty instead of using the Search API.
> >
> > Basically - I'm trying to use the track paramter to track a keyword.
> > However, when I run this code - it just times out - nothing occurs.
> > Perhaps I'm not using the track parameter correctly?
> >
> > I know I'm just dumping the code right now - but it was merely for
> > test.
> >
> > My ad-hoc code is below:
> >
> > // twitter_stream.php
> > <?
> > $fp = fopen("http://username:passw...@stream.twitter.com/1/statuses/
> > filter.json?track=ttl,wine", "r");
> > while($data = fgets($fp))
> > {
> >    $new_data = json_decode($data);
> >
> >        foreach($status as $new_data)
> >        {
> >                var_dump($status);
> >                echo "<hr>";
> >        }
> > }
> > ?>
> >
> > Thanks for the help!
> >
> > Greg
>

Reply via email to