On Mon, 2010-08-09 at 13:32 +0200, Bostjan Skufca wrote:
> Hi all!
> 
> I am developing a small PHP extension and I ATM can't figure out how to get
> to $_SERVER['SCRIPT_FILENAME'] content while in PHP_RINIT or PHP_RSHUTDOWN
> function. Can someone please hint me with this one?

The simple answer is: You can't. The closest you can get is a char *
SG(request_data).request_uri

The more complex answer is: It is only stored for being used in
$_SERVER. So you can read it from there. The engine has a "just in time"
mode to avoid creating _SERVER when not needed, we need it so we first
have to trigger the creation of that variable, then one can search
through the global symbol table and then search in there:


zval **server, **tmp;
zend_auto_global_disable_jit("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"),  
(void**)&server) == FAILURE || Z_TYPE_PP(server) != IS_ARRAY) {
    /* error handling */
    return;
}
if (zend_hash_find(Z_ARRVAL_PP(server), "SCRIPT_FILENAME", 
sizeof("SCRIPT_FILENAME"), (void**)&tmp) == FAILURE || Z_TYPE_PP(tmp) != 
IS_STRING) {
    /* error handling */
    return;
}
/* work with tmp */

As this accesses the userspace $_SERVER you should do this during RINIT,
else the value might be wrong. While this adds some cost to every
request (populating $_SERVER plus two hash lookups), it can be optimized
a tiny bit by precalculating the hash and using zend_hash_quick_find().

The code above is untested.

johannes



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

Reply via email to