2010/8/10 Johannes Schlüter <johan...@schlueters.de>

> Hi,
>
> On Tue, 2010-08-10 at 17:24 +0200, Bostjan Skufca wrote:
> > I've been digging a little deeper and have figured out that I probably
> > could retrieve what I want (realpath of first executed file) from
> > included_files hash (first entry, obviously). Unfortunately, doing it
> > like this (sampled from get_included_files() implementation):
>
> Interesting idea. Didn't think about that. But it isn't reliable either:
> If an auto prepend file is set this will be in the list first.
>

So simple thing, so easy to overlook...
But I believe it is fairly easy to check if autoprepend is enabled and use
second item from the list in that case, or (in case that is not posible)
introduce new ini setting for that matter.


>     char *hentry;
> >     zend_hash_internal_pointer_reset(&EG(included_files));
> >     zend_hash_get_current_key(&EG(included_files), &hentry, NULL, 1);
> >     printf("%s", hentry);
>
> I think you want the value, not the key. To be precise you want the
> value for key 0. -> zend_hash_find()
>

Aaaa, again, so simple. I feel such a newbie, but obviously not without a
reason :)


But thinking about this idea I had another idea: Use the userland
> stacktrace. While this won't work in RINIT/RSHUTDOWN but you'd have to
> hook into the execution somewhere. Would look something like this:
>
> char *filename;
> struct _zend_execute_data current_frame = EG(curent_execute_data);
> do {
>    if (current_frame->type != ZEND_INTERNAL_FUNCTION) {
>        filename = current_frame->filename;
>    }
> } while (current_frame = current_frame->prev_execute_data);
> php_printf("%s, filename);
>
> Again: Not tested at all.
>

This would probably mean I have to modify PHP itself or call certain
extension function from within PHP script?
(That is what I am desperately trying to avoid.)


Again, thanks for all the help!
b.

Reply via email to