Actually, I was a little bit wrong... It's not that it's buffering the
entire request... only the first 1180 or so bytes....

The first php_stream_gets() call in http_fopen_wrapper.c requests a line of
data, php_stream_gets reads in a chunk (1448 bytes?) via
php_stream_fill_read_buffer().  The data read into buffer here includes the
headers PLUS (in the case of www.php.net the first 1180 or so bytes of
content)

This seems like it could produce unexpected results in other cases as well.
Take the following example:

<?php
  /* Open this script as our text file */
  $fp = fopen("test.php","r");
  /* Display the first line unfiltered */
  echo fgets($fp);
  /* rot13 the rest */
  stream_filter_append($fp, "string.rot13");
  while ($str = fgets($fp))
    print $str;
  fclose($fp);
?>

We might expect to get "<?php" output normally and all other lines
ROT13ed... The reality is that the entire file is output normally because
the initial "echo fgets($fp);" reads the entire file (because its so small)
into its buffer.  In the case of a large file there would be a cutoff
seemingly random cutoff point where the unfiltered section ends and the
filtered one begins.

It seems to me that the data should be read into buffer unfiltered at ALL
times whether or not filters exist, only when the data is actually used
(whether it's taken from the buffer or directly from the stream) should the
filters be applied.

-Pollita

> It should not happen, and there is code in the http opener that *should*
> avoid this, because it has negative implications for including files via
> http.
>
> I will take a look when I have more time...
>
> >   Now, the point I've managed to completely skirt around.... I
discovered
> > something a little disturbing about the http wrapper (and presumably
other
> > network wrappers as well).  The following script (with or without the
above
> > patch applied) will *NOT* uppercase the content retrieved from the url
> > because the content is read into buffer immediately (on the fopen call)
and
> > the filter isn't applied until the next line.
> >
> > <?php
> >   $fp = fopen("http://www.php.net/";, "r");
> >   /* the data is already sitting in buffer */
> >   stream_filter_append($fp, "string.toupper");
> >   while ($str = fgets($fp))
> >     print $str;
> >   fclose($fp);
> > ?>
> >



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to