Search code examples
cwindowsphpphp-extensionphp-internals

Reading php.ini using zend for PHP extension (not PHP language)


I am trying to read some settings from php.ini using zend. The API that I am using is

long zend_ini_long(char *name, uint name_length, int orig)

But it always returns 0. I have double checked the name and also made sure that the value I am specifying in php.ini is greater then 0. Is there anything I am missing?


Solution

  •  long maxwait = zend_ini_long("max_execution_time",
         sizeof("max_execution_time"), 0);
    

    The problem is that ZEND_STRL is not returning the right length for the way that this API is intended to be used, so don't use it.

    I should add that most of the hash tables maintained internally by PHP assume that the NUL terminator character is included in the length of the string being hashed (its part of the overall binary safety concept), which is why we use sizeof() rather than strlen() or sizeof()-1.