1

这是代码:

<?php
class curlWrap {

    protected $buffer;
    function stream_open($path, $mode, $options, &$opened_path) {
        return true;
    }

    public function stream_write($data) {
        // Extract the lines ; on y tests, data was 8192 bytes long ; never more
        $lines = explode("\n", $data);

        // The buffer contains the end of the last line from previous time
        // => Is goes at the beginning of the first line we are getting this time
        $lines[0] = $this->buffer . $lines[0];

        // And the last line os only partial
        // => save it for next time, and remove it from the list this time
        $nb_lines = count($lines);
        $this->buffer = $lines[$nb_lines-1];
        unset($lines[$nb_lines-1]);

        for ($i=0; $i<count($lines); $i++) {
            $curDecodedTweet = json_decode($lines[$i]);
            if (property_exists($curDecodedTweet,"text")) {
                $tweetText = $curDecodedTweet->text;
                echo "$tweetText\n";
            }
        }

        return strlen($data);
    }
}
{
stream_wrapper_register("curlWrap","curlWrap") or die("Failed to register protocol");
$fp = fopen("curlWrap://tweetStream.txt","r+");

set_time_limit(60);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://stream.twitter.com/1/statuses/sample.json");
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypass");
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: api.twitter.com'));
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
?>

但如果我执行这个......会出现这个错误:

警告:curl_setopt() [function.curl-setopt]: curlWrap::stream_cast 未实现!在 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\catturaTweets\riproviamo.php 第 44 行

警告:curl_setopt() [function.curl-setopt]: curlWrap::stream_cast 未实现!在 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\catturaTweets\riproviamo.php 第 44 行

警告:curl_setopt() [function.curl-setopt]:不能将用户空间类型的流表示为 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\catturaTweets\riproviamo.php 中的 STDIO 文件*第 44 行这是什么原因?很抱歉给您带来麻烦,谢谢

4

0 回答 0