Help with codebird library

codebird
php

#1

Hi everyone,

I’m developing a php web application using codebird php library and I was wondering if any of you can help me, I tried to connect to a endpoint but my english is so bad and I don’t understand the documentation, if you can send me an example to view how to connect and make a track request I’d appreciate it very much.

Now i have that code:

<?php
 require_once('codebird.php');
 \Codebird\Codebird::setConsumerKey('CONSUMER KEY', 'CONSUMER SECRET');

 $cb = \Codebird\Codebird::getInstance();
 $cb->setToken('TOKEN KEY', 'TOKEN SECRET');

 function some_callback($message){
   if ($message !== null) {
	echo "<p>";
	print_r($message);
	echo "</p>";
	flush();
   }
   if (time() - $GLOBALS['time_start'] >= 60) {
  	return true;
   }
   return false;
 }
 $cb->setStreamingCallback('some_callback');
 $GLOBALS['time_start'] = time();
 $reply = $cb->statuses_filter('track=happy');
?>

How can i do that the request never stop automatically?

Thanks!


#2

The code you showed will stop after 60 seconds. Your callback function (some_callback) return parameter controls when Codebird should stop consuming the streaming API:

  • return false if you don’t want to stop yet
  • return true if you want to stop now

So, to continue infinitely, just remove the if-condition (if (time() - $GLOBALS…) along with its curly braces and content.


#3

Oh, thanks Jublonet, then if i return false all time the stream don’t stop.

Thanks mate!


#4

Unless your PHP script is killed – www.php.net/set_time_limit.