PHP Classes

PHP.ini Settings: Manage the PHP configuration values of php.ini

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 260 All time: 7,786 This week: 173Up
Version License PHP version Categories
php-settings 1.0.0BSD License5.6PHP 5, Systems administration, Text p..., L..., C..., P...


This package can manage the PHP configuration values of php.ini.

It can read the values of a php.ini file, get option values, change option values and save the modified settings to the current or a new php.ini file.

The package attempts to validate the types of values passed to each setting using a configuration CSV file that has the type information for each value.

The original formatting and comments are preserved when writing back the modified contents. Quoted values will remain quoted, and unquoted values will remain unquoted. So if you use a diff utility you can easily note what was changed.

Innovation Award
PHP Programming Innovation award nominee
January 2017
Number 2
PHP uses a php.ini file to read values that configures many aspects of the way PHP code works.

If you change one configuration value but set it to an incorrect type, PHP may not work as you expect and you may take a long time to figure what you did wrong.

The class provides a solution that can not only read and change php.ini settings, but it also can verify if you are setting those values to the correct types that PHP is expecting.

It uses a knowledge base file that contains the types of values that PHP expects for most of the configuration settings, so it can validate all the values and tell you if you set any values incorrectly.

Manuel Lemos
Picture of Christian Vigh
  Performance   Level  
Name: Christian Vigh <contact>
Classes: 32 packages by
Country: France France
Age: 57
All time rank: 13810 in France France
Week rank: 10 Up1 in France France Up
Innovation award
Innovation award
Nominee: 20x

Winner: 3x



        This example file demonstrates the use of the PhpSettings class.

require_once ( 'PhpSettings.phpclass' ) ;

    if (
php_sapi_name ( ) != 'cli' )
        echo (
'<pre>' ) ;

// Load settings defined in file "example.php.ini"
$settings = new PhpSettings ( 'example.php.ini' ) ;

// Change the "memory_limit" setting.
    // Note that we could have used :
    // $settings -> Set ( 'memory_limit', '127M' ) ;
$settings -> memory_limit = '127M' ;
    echo (
"Memory limit set to 127M instead of 1024M\n\n" ) ;

// Enable extensions that are already listed in file 'example.php.ini', but are commented out
echo ( "Enabling disabled extensions 'mbstring' and 'exif'\n\n" ) ;
$settings -> EnableExtension ( 'mbstring' ) ;
$settings -> EnableExtension ( 'exif' ) ;

// Enable an extension that is not listed in file 'example.php.ini'
echo ( "Enabling undefined extension 'unknown'\n\n" ) ;
$settings -> EnableExtension ( 'unknown' ) ;

// Display the list of currently defined extensions ; you should see the 'mbstring' and 'exif' extensions,
    // which were initially listed in the 'example.php.ini' file but commented out, along with the 'unknown'
    // extension, which has just been added
echo ( "List of enabled extensions :\n" ) ;
    echo (
"--------------------------\n" ) ;
    echo (
"\t" . implode ( "\n\t", $settings -> GetEnabledExtensions ( ) ) . "\n\n" ) ;

// Save the modified contents to file 'example.php.out'
$settings -> SaveTo ( 'example.php.out' ) ;
    echo (
"Modifications saved to file example.php.out\n\n" ) ;

// Run a comparison between the original version ('example.php.ini') and the modified one ('example.php.out')
exec ( 'diff -Z example.php.ini example.php.out', $output ) ;
    echo (
"Comparison results :\n" ) ;
    echo (
"------------------\n" ) ;
    echo (
"\t" . implode ( "\n\t", $output ) ) ;

  Files folder image Files  
File Role Description
Files folder imageData (3 files)
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file example.php.ini Data Auxiliary data
Accessible without login Plain text file example.php.out Output Example output
Plain text file Path.phpclass Class Class source
Accessible without login Plain text file PhpSettings.csv Data Auxiliary data
Plain text file PhpSettings.phpclass Class Class source
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  Data  
File Role Description
  Accessible without login Plain text file mapsettings.phs Appl. Generator script for PhpSettings.csv
  Accessible without login Plain text file settings-20161106.csv Output PhpSettings.csv file contents
  Accessible without login Plain text file settings-20161106.txt Data PHP Settings description

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:7,786
This week:173Up