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 FILE* として表すことはできません44行目 その理由は何ですか? お手数をおかけして申し訳ありません。

4

0 に答える 0