get_path($path));
  }

  public function stream_open($path, $mode, $options, &$opened_path) {
    print "stream_open($path)\n"; flush();
    $this->handle = fopen($this->get_path($path), $mode);
    print "steam_open => $this->handle\n"; flush();
    return (boolean) $this->handle;
  }

  public function stream_write($data) {
    print "stream_write\n"; flush();
    return fwrite($this->handle, $data);
  }

  public function stream_close() {
    print "stream_close\n"; flush();
    fclose($this->handle);
  }

  public function stream_stat() {
    print "stream_stat\n"; flush();
    return fstat($this->handle);
  }

  public function stream_read($count) {
    print "stream_read($count)\n"; flush();
    return fread($this->handle, $count);
  }

  public function stream_eof() {
    print "stream_eof()\n"; flush();
    return feof($this->handle);
  }

}

stream_wrapper_register('temp', 'TempStream') or die('Failed to register protocol temp://');

// copy 1: file to stream wrapper
print "============================================\n";
$ok = copy('/tmp/source.txt', 'temp://destination.txt');
print "copy1 = $ok\n";

// copy 2: stream wrapper to file
print "============================================\n";
$ok = copy('temp://destination.txt', '/tmp/source.txt');
print "copy2 = $ok\n";

// copy 3: same file as stream wrapper to file
print "============================================\n";
$ok = copy(sys_get_temp_dir() . '/destination.txt', '/tmp/source.txt');
print "copy3 = $ok\n";

?>