Server IP : 103.119.228.120 / Your IP : 3.137.169.56 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /scripts/ |
Upload File : |
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - scripts/set_php_memory_limits Copyright 2022 cPanel, L.L.C. # All rights reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited package scripts::set_php_memory_limits; use strict; use warnings; use Getopt::Long (); use Cpanel::Sys::Hardware::Memory (); use Whostmgr::API::1::Lang::PHP (); use Cpanel::Imports; use Data::Dumper; our $gsw_message_dir = '/var/cpanel/gsw_messages'; our $message_caller_depth = 1; exit( run(@ARGV) ) if !caller(); sub run { my @args = @_; my ( $run, $gsw ); Getopt::Long::GetOptionsFromArray( \@args, "run" => \$run, "gsw" => \$gsw, ); if ( not( $run or $gsw ) ) { die qq{Must pass "--run" flag to execute script.\nThis script will adjust the memory_limit setting for all cPanel PHPs installed in /opt/cpanel/ to a reasonable setting based on the servers available memory.\n}; } # We want to raise the PHP memory_limit if possible in regards to the amount of installed memory they have on the system my $installed_memory = eval { Cpanel::Sys::Hardware::Memory::get_installed(); }; my ( $mid_mem, $high_mem ) = qw( 2000 4000 ); my $set_memory; if ( $installed_memory < $mid_mem ) { $set_memory = '32M'; } elsif ( ( $installed_memory >= $mid_mem ) && ( $installed_memory < $high_mem ) ) { $set_memory = '64M'; } elsif ( $installed_memory >= $high_mem ) { $set_memory = '128M'; } eval { my $installed_versions = Whostmgr::API::1::Lang::PHP::php_get_installed_versions(); my $bytes = $installed_memory * 1024 * 1024; # Cpanel::Sys::Hardware::Memory is MiB if ($gsw) { create_gsw_message( "php_memory_limit", "[% locale.maketext('We changed the webserver’s PHP “[output,strong,_1]” directive to “[_2]” to better support your server’s [format_bytes,_3] of memory.', 'memory_limit', '$set_memory', '$bytes') %]\n", "[% locale.maketext('You can change it at anytime via the [output,url,_1,MultiPHP INI Editor in WHM,target,_blank].', '../scripts2/multiphp_ini_editor') %]\n" ); } foreach my $php_version ( @{ $installed_versions->{versions} } ) { my $metadata = {}; Whostmgr::API::1::Lang::PHP::php_ini_set_directives( { version => $php_version, directive => "memory_limit:$set_memory" }, $metadata ); logger->info("The memory limit for $php_version has been set to $set_memory based on the servers installed memory ($installed_memory MiB)"); if ( !$metadata->{'result'} ) { logger->error("There was a problem setting the memory_limit in your php.ini files.\n"); } } }; return 0; } sub create_gsw_message { my ( $name, @lines ) = @_; # check for non words if ( $name =~ /\W/ ) { logger->warn("'$name' is not valid as a GSW message filename.\n"); return; } # create the directory for custom Getting Started Wizard message tt files if ( !-e $gsw_message_dir ) { mkdir $gsw_message_dir, 0755; } if ( open( my $fh, ">", "$gsw_message_dir/$name.tt" ) ) { foreach my $line (@lines) { # concat anything passed into the subroutine. print {$fh} $line; } close $fh; } else { logger->warn("Could not write to GSW message directory: $!"); return; } return 1; } 1;