On Mon, 24 Feb 2003, Rasmus Lerdorf wrote: > if (stream) { > if (self->is_pipe) { > stream->flags |= PHP_STREAM_FLAG_NO_SEEK; > } else { > stream->position = ftell(file); > } > } > > We should be able to skip that ftell() call on a script or include file we > have just opened, right?
Yes; prior to my fixes this week, the ftell was sometimes important; streams should be able manage just fine without it now. > _php_stream_open_wrapper_as_file() what are you trying to guard against > with that stream_cast call? > > if (php_stream_cast(stream, > PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, > (void**)&fp, REPORT_ERRORS) == FAILURE) > { > php_stream_close(stream); > if (opened_path && *opened_path) > efree(*opened_path); > return NULL; > } > > We have already stat()'ed the file to death. We know it is there, that we > are allowed to open it, etc. What could go wrong that the open call just > above it wouldn't have caught? Is it just a case of getting too general > and we need a special-case simpler function for the most common operation > of simply opening script files? Yes and no. (we need this approach in order to be able to include/require from any wrapper). In php_stream_cast, we need to ensure that when we pass back the file pointer, it is seeked to the correct offset (as we see it) in the file. This is because the underlying FILE* has its own buffer, and its own idea of the file position. [Yes, using FILE*/stdio streams with buffers is causing headaches, which is why I'm moving away from them in PHP 5]. Admittedly, when opening the file for the first time, we do not need to seek - so we can avoid it by passing a flag (OR'd with the REPORT_ERRORS flag). I'm sure we can eliminate those seeks. Are there any other areas in the streams code that you can see that could do with a syscall tune-up? --Wez. -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php