views:

296

answers:

3

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?

A: 

Do you need to read php.ini file? Maybe the information is available with phpinfo()?

But if you must are the "www user" allowed to read the file at all? If you change permissions does it still return 0?

Johan
I am actually writing a php extension in C. I have read couple of tutorials and they don't mention anything regarding changing permissions so extensions can read php.ini.Any idea where can I change permissions settings for php xtensions?
cornerback84
I was thinking about something like this "ls -l /etc/php5/apache2/php.ini" and then chmod if needed.
Johan
No its not working. Btw I am using Windows.
cornerback84
A: 

You can use the standard php function: ini_get('var-name');

Example:

ini_get('include_path');
lo_fye
+3  A: 
 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.

Wez Furlong
It worked, thanks alot.
cornerback84
+1, It's rather a nasty trap that some of the functions need the sizeof(string) and some need sizeof(string) - 1, it's tripped me up before.
therefromhere
Ok, now I am trying to read settings that I have written in php.ini. But I am not able to retrieve it. It always returns "".I am using zend_ini_string(field_name, sizeof(field_name), 0).Its strange for me that it reads some settings and not other settings. Is there some kind of naming that we have to use?
cornerback84
are you reading PHP's own settings, or those from your extension? If the latter, did you register those INI settings in your MINIT function?
Wez Furlong
I was only doing PHP_INI_BEGIN and PHP_INI_END as per a tutorial I followed.After you told to register in MINIT function, I have to check other default php extension to see how they were doing. Its working ok now.Thanks alot.
cornerback84