il codice è il seguente...Si connette ad un api twitter che restituisce un flusso dei tweet circolanti in esso.. e vorrei che girasse per quanto dico io... ma dopo un po di tempo... circa mezz'ora dentro $fp non trovo più niente (io lo vorrei far girare per qualche giorno)... c' è qualcuno che mi sa spiegare il perché??
Forse esiste una funzione migliore x connettersi ad un flusso di dati in streaming...se fosse me la potete suggerire???
Un grazie infinito a chi risponderà...
Forse esiste una funzione migliore x connettersi ad un flusso di dati in streaming...se fosse me la potete suggerire???
Un grazie infinito a chi risponderà...
PHP:
$fp = fsockopen("ssl://stream.twitter.com", 443, $errno, $errstr, 30);
$ini=time();
$fine=time();
$passati=$fine-$ini;
if (!$fp)
{
die ("ERROR: Twitter Stream Error: failed to open socket");
} else
{
//
// build the request
//https://'.'stream.twitter.com/1/statuses/sample.json
$request = "GET /1/statuses/sample.json";
$request .= " HTTP/1.1\r\n";
$request .= "Host: stream.twitter.com\r\n";
$request .= "Authorization: Basic ";
$request .= base64_encode($this->m_username . ':' . $this->m_password);
$request .= "\r\n\r\n";
//
// write the request
//
fwrite($fp, $request);
//
// set it to non-blocking
//
stream_set_blocking($fp, 0);
//(!feof($fp))&&
while(($passati<($this->durata)))
{
$fine=time();
$passati=$fine-$ini;
$read = array($fp);
$write = null;
$except = null;
$res = stream_select($read, $write, $except, 600, 0);
if ( ($res === false) || ($res == 0) )
{
break;
}
//
// read the JSON object from the socket
//
$json = fgets($fp);
if ( ($json !== false) && (strlen($json) > 0) )
{
//
// decode the socket to a PHP array
//
$data = json_decode($json, true);
if ($data)
{
//
// process it
//
$this->process_tweet($data);
}
}
}
}
Ultima modifica: