Getting path of currently executing file from within stream_opener handler

php.internals

Marshall Greenblatt

18 years ago
Hi All, I have a stream wrapper implementation that needs to properly resolve relative paths. For example, say I have a file structure like the following: file1.php dir/file2.php dir/file3.php file4.php file1.php contains: <?php include 'dir/file2.php'; ?> file2.php contains: <?php include 'file3.php; ?> My implementation of php_stream_wrapper_ops.stream_opener will see a path value of "dir/file2.php" for the first include request and a path value of "file3.php" for the second include request. When receiving the second include request, I need to know that the file currently being processed is "dir/file2.php" so that I can properly resolve "file3.php" to "dir/file3.php". I can't simply "remember" the last value passed to stream_opener because I have no way of knowing when processing of a particular file has ended. For instance: file1.php contains: <?php include 'dir/file2.php'; include 'file4.php'; ?> file2.php contains: <?php include 'file3.php; ?> Is there a method that can be used from within the stream_opener handler function to retrieve the path of the file currently being processed? Alternately, is there a way to hook into the code processing routines so that I can keep track of when execution of a particular file begins and ends? Or is there an even better option that I'm missing? Any thoughts would be greatly appreciated :-). Thanks, Marshall

Antony Dovgal

18 years ago
On 17.11.2007 11:23, Marshall Greenblatt wrote:
> Is there a method that can be used from within the stream_opener > handler function to retrieve the path of the file currently being > processed?
Yes, zend_get_executed_filename(). Though, I believe you actually need expand_filepath(), which does exactly what you said, i.e. resolves relative paths.
-- Wbr, Antony Dovgal

Marshall Greenblatt

18 years ago
Hi Antony, On Nov 17, 2007 5:21 AM, Antony Dovgal <tony@daylessday.org> wrote:
> On 17.11.2007 11:23, Marshall Greenblatt wrote: > > Is there a method that can be used from within the stream_opener > > handler function to retrieve the path of the file currently being > > processed? > > Yes, zend_get_executed_filename(). > Though, I believe you actually need expand_filepath(), which does exactly what you said, > i.e. resolves relative paths.
Thank you for your quick response. zend_get_executed_filename() allowed me to do exactly what I was looking for.
> > -- > Wbr, > Antony Dovgal >
Regards, Marshall