The settings of the “RAM” add-on in billing affects the RAM allocated to the user in ISPmanager. But you use ISPmanager Lite, where there are no restrictions on RAM. Restriction on RAM is only in ISPmanager Business.
<?xml version="1.0" encoding="UTF-8"?> <mgrdata> <handler name="hiweb_vhostram.php" type="cgi"> <event name="vhost.edit" after="yes"/> </handler> </mgrdata>
#!/usr/bin/php <?php $logFile = '/var/www/log/hiweb_vhostram.log'; $logInfo = array(); //////// // $fileSettings = dirname( dirname( __FILE__ ) ) . '/etc/billmgr.conf.d/db.conf'; if( file_exists( $fileSettings ) ){ $fileSettingsContent = file( $fileSettings, FILE_IGNORE_NEW_LINES ); foreach( $fileSettingsContent as $line ){ $arr = explode( ' ', trim( $line ) ); if( count( $arr ) != 2 ) continue; list( $lineKey, $lineValue ) = $arr; if( $lineKey == 'DBHost' ) $DBHost = $lineValue; if( $lineKey == 'DBUser' ) $DBUser = $lineValue; if( $lineKey == 'DBPassword' ) $DBPassword = $lineValue; if( $lineKey == 'DBName' ) $DBName = $lineValue; } $mysql = new mysqli( $DBHost, $DBUser, $DBPassword, $DBName ); //$R = array($_GET, $_POST, $_SERVER); if( $mysql ){ // RAM $priceListResult = $mysql->query( 'SELECT id FROM pricelist WHERE itemtype=(SELECT id FROM itemtype WHERE name="RAM" AND statparam != "")' ); $priceList = reset( $priceListResult->fetch_assoc() ); /// if(!isset($_SERVER['PARAM_addon_'.$priceList])){ $logInfo[] = 'error: no parameter [PARAM_addon_'.$priceList.'] in $_SERVER'; }else{ $additionMemory = $_SERVER['PARAM_addon_'.$priceList]; /// $userLogin = $_SERVER['PARAM_username']; if( trim( $userLogin ) == '' ){ //do nothing } else{ $logInfo[] = 'select user ['.$userLogin.']'; /// //$userResult = $mysql->query( 'SELECT * FROM itemparam WHERE intname="username" AND item="' . $userId . '"' ); //$userData = $userResult->fetch_assoc(); //$userLogin = $userData['value']; /// /// $phpIniFiles = array( '/var/www/php-bin/' . $userLogin . '/php.ini', '/var/www/' . $userLogin . '/data/php-bin/.php.ini', '/var/www/' . $userLogin . '/data/php-bin/php.ini' ); // foreach( $phpIniFiles as $phpIni ){ $B = ''; if( !file_exists( $phpIni ) ){ $logInfo[] = 'error: file not exists!'; }elseif( !is_readable( $phpIni ) ){ $logInfo[] = 'error: file not readable!'; }elseif( !is_file( $phpIni ) ){ $logInfo[] = 'error: this is dir, not file!!!'; }else{ $content = file_get_contents( $phpIni ); preg_match('/^memory_limit = (\d){1,4}[a-zA-Z]?$/im',$content, $match); if(count($match) > 0){ $line = trim(reset($match)); // $lineExplode = explode( ' = ', $line ); $lineExplode[1] = $additionMemory . 'M'; $newLine = implode( ' = ', $lineExplode ); // if( trim( $line ) != trim( $newLine ) ){ $logInfo[] = file_put_contents($phpIni, str_replace($line,$newLine,$content)) ? $line.' → '.$newLine : 'error: file_put_content'; }else{ $logInfo[] = 'not change: '.$line.' → '.$newLine; } }else{ $add = 'memory_limit = ' . $additionMemory.'M'; $content .= chr( 13 ) . chr( 10 ) . $add . chr( 13 ) . chr( 10 ); $logInfo[] = file_put_contents($phpIni, $content) ? '+ '.$add : 'error add: file_put_content'; } } } } } } else { $logInfo[] = 'error: mysql not connected!'; } } file_put_contents($logFile, print_r( $logInfo, 1 ) ); echo '<?xml version="1.0" encoding="UTF-8"?><doc>'; echo '</doc>'; ?>
<?php function return_bytes( $val ){ $val = trim( $val ); $last = strtolower( $val[ strlen( $val ) - 1 ] ); switch( $last ){ // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } /** * * @param $size - INT * @return string */ function size_format( $size ){ $size = intval( $size ); if( $size < 1024 ){ return $size . " bytes"; }else if( $size < ( 1024 * 1024 ) ){ $size = round( $size / 1024, 1 ); return $size . " KB"; }else if( $size < ( 1024 * 1024 * 1024 ) ){ $size = round( $size / ( 1024 * 1024 ), 1 ); return $size . " MB"; }else{ $size = round( $size / ( 1024 * 1024 * 1024 ), 1 ); return $size . " GB"; } } $memory = size_format( return_bytes( ini_get( 'memory_limit' ) ) ); echo '<phpmem>'; echo '<val>' . $memory . '</val>'; echo '</phpmem>';
Source: https://habr.com/ru/post/316264/
All Articles