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?

1
  • Here is the code that I have written: long maxwait = zend_ini_long(ZEND_STRL("max_execution_time"), 0); ZEND_STRL(str) is a zend macro which resolves to (str), (sizeof(str)-1). This code is written in a php extension (written in C). Commented Aug 18, 2009 at 7:51

3 Answers 3

3
 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.

Sign up to request clarification or add additional context in comments.

4 Comments

+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.
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?
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?
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.
0

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?

2 Comments

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?
I was thinking about something like this "ls -l /etc/php5/apache2/php.ini" and then chmod if needed.
0

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

Example:

ini_get('include_path');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.