api
2 years ago
backups
2 years ago
external
2 years ago
integrations
2 years ago
media
2 years ago
media-library
2 years ago
modules
2 years ago
photon
2 years ago
png2jpg
2 years ago
resize
2 years ago
s3
2 years ago
smush
2 years ago
stats
2 years ago
webp
2 years ago
class-animated-status-controller.php
2 years ago
class-array-utils.php
2 years ago
class-attachment-id-list.php
2 years ago
class-backup-size.php
2 years ago
class-cli.php
2 years ago
class-configs.php
2 years ago
class-controller.php
2 years ago
class-core.php
2 years ago
class-deprecated-hooks.php
2 years ago
class-error-handler.php
2 years ago
class-file-system.php
2 years ago
class-helper.php
2 years ago
class-installer.php
2 years ago
class-modules.php
2 years ago
class-optimization-controller.php
2 years ago
class-plugin-settings-watcher.php
2 years ago
class-rest.php
2 years ago
class-server-utils.php
2 years ago
class-settings.php
2 years ago
class-smush-file.php
2 years ago
class-stats.php
2 years ago
class-upload-dir.php
2 years ago
class-server-utils.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Smush\Core; |
| 4 | |
| 5 | class Server_Utils { |
| 6 | /** |
| 7 | * @var string |
| 8 | */ |
| 9 | private $mysql_version; |
| 10 | |
| 11 | public function get_server_type() { |
| 12 | if ( empty( $_SERVER['SERVER_SOFTWARE'] ) ) { |
| 13 | return ''; |
| 14 | } |
| 15 | |
| 16 | $server_software = wp_unslash( $_SERVER['SERVER_SOFTWARE'] ); |
| 17 | if ( ! is_array( $server_software ) ) { |
| 18 | $server_software = array( $server_software ); |
| 19 | } |
| 20 | |
| 21 | $server_software = array_map( 'strtolower', $server_software ); |
| 22 | $is_nginx = $this->array_has_needle( $server_software, 'nginx' ); |
| 23 | if ( $is_nginx ) { |
| 24 | return 'nginx'; |
| 25 | } |
| 26 | |
| 27 | $is_apache = $this->array_has_needle( $server_software, 'apache' ); |
| 28 | if ( $is_apache ) { |
| 29 | return 'apache'; |
| 30 | } |
| 31 | |
| 32 | return ''; |
| 33 | } |
| 34 | |
| 35 | public function get_memory_limit() { |
| 36 | if ( function_exists( 'ini_get' ) ) { |
| 37 | $memory_limit = ini_get( 'memory_limit' ); |
| 38 | } else { |
| 39 | // Sensible default. |
| 40 | $memory_limit = '128M'; |
| 41 | } |
| 42 | |
| 43 | if ( ! $memory_limit || - 1 === $memory_limit ) { |
| 44 | // Unlimited, set to 32GB. |
| 45 | $memory_limit = '32000M'; |
| 46 | } |
| 47 | |
| 48 | return intval( $memory_limit ) * 1024 * 1024; |
| 49 | } |
| 50 | |
| 51 | public function get_memory_usage() { |
| 52 | return memory_get_usage( true ); |
| 53 | } |
| 54 | |
| 55 | private function array_has_needle( $array, $needle ) { |
| 56 | foreach ( $array as $item ) { |
| 57 | if ( strpos( $item, $needle ) !== false ) { |
| 58 | return true; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | public function get_mysql_version() { |
| 66 | if ( ! $this->mysql_version ) { |
| 67 | global $wpdb; |
| 68 | $this->mysql_version = $wpdb->db_version(); |
| 69 | } |
| 70 | return $this->mysql_version; |
| 71 | } |
| 72 | |
| 73 | public function get_max_execution_time() { |
| 74 | return (int) ini_get( 'max_execution_time' ); |
| 75 | } |
| 76 | |
| 77 | public function get_user_agent() { |
| 78 | return ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; |
| 79 | } |
| 80 | } |
| 81 |