Here is a working example of how to do /track:
$count = 1;
$startparsing = false;
$keyword_needles[] = 'keyword1';
$keyword_needles[] = 'keyword2';
$keyword_needles[] = 'keyword3';
$keyword_needles[] = 'keyword4';
// if your keywords have spaces, they must be urlencoded (twitter does not support phrases, only the first keyword will be used, the space character and after will be ignored)
foreach ($keyword_needles AS $i=>$needle) {
$keyword_needles[$i] = urlencode($needle);
}
$poststr = 'track=' . implode(',', $keyword_needles);
$fp = fsockopen("
stream.twitter.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";
} else {
$out = "POST /track.json HTTP/1.1\r\n";
$out .= "Host:
stream.twitter.com\r\n";
$out .= "User-Agent: YourUserAgent\r\n";
$out .= "Referer:
http://yourdomain.com\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Authorization: Basic " . base64_encode("username:password")."\r\n";
$out .= "Content-length: " . strlen($poststr) . "\r\n";
$out .= "Connection: Close\r\n\r\n";
$out .= $poststr . "\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$line = fgets($fp, 4096);
if ($startparsing) {
if (trim($line) != '') {
//echo trim($line) . "\n";
$tweet_obj = json_decode(trim($line));
// do your stuff here
}
}
else {
// view the header lines: uncomment the below line
//echo trim($line) . "\n";
$header_arr[] = $line;
$headercount = count($header_arr)-1;
if (trim($header_arr[$headercount]) == '') {
$startparsing = true;
$count = 1;
unset($header_arr, $headercount);
}
}
if (trim($line) != '') $count++;
}
fclose($fp);