What are some common pitfalls when using ini_set() in PHP?

One common pitfall when using ini_set() in PHP is that it may not work if the directive you are trying to set is marked as PHP_INI_SYSTEM in the php.ini file. To solve this issue, you can use the ini_get_all() function to check if a directive is changeable at runtime before attempting to set it with ini_set().

$directive = 'memory_limit';
$directiveInfo = ini_get_all();
if(isset($directiveInfo[$directive]) && $directiveInfo[$directive]['changable']){
    ini_set($directive, '256M');
} else {
    echo "Directive $directive is not changeable at runtime.";
}