天天看點

PHP檢測伺服器是否當機

ping指令行指令檢測:

/**
 * PHP指令行ping
 * @param [str] $address 域名或者IP
 * @return [arr] ['status'=>1|0,'data'=>'響應資訊']
 */
function pingAddress($address) {

    if(preg_match('/WIN/', PHP_OS)){
        // Windows 伺服器下
        exec("ping -n 1 $address", $output, $return_var);
    }else{
        // Linux 伺服器下
        exec("ping -c 1 $address", $output, $return_var);
    }

    $output = implode(';',array_filter($output));
    if(preg_match('/Reply from/', $output)){
        preg_match('/Reply[\s]+from[\s\S]+:([\S\s]+);/U', $output,$match);
        $match = $match[1];
        $msg = trim($match);
        if(preg_match('/time/', $msg)){
            $status = 1;
        }else{
            $status = 0;
        }
    }else{
        $msg = $output;
        $status = 0;
    }

    // 解析響應描述資訊
    $data = array('status'=>$status,'data'=>$msg);
    return $data;
}      

Linux檢視機器目前fpm的子程序數:

while :; do ps aux|grep -c php-fpm;sleep 1;done      

3G書城預設FPM配置:

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /data/log/weblog/php-fpm.log
# 能打開的最大檔案描述符
rlimit_files = 4096
[www]
# FPM監聽端口
listen = 127.0.0.1:9000
user = nobody
group = nobody

# 設定程序管理器如何管理子程序 - 動态
pm = dynamic
# pm 設定為dynamic時表示最大可建立的子程序的數量
pm.max_children = 400
# 啟動時建立的子程序的數量
pm.start_servers = 20
# 所需的最小空閑伺服器程序數
pm.min_spare_servers = 10
# 所需的最大空閑伺服器程序數
pm.max_spare_servers = 90
# FPM 狀态頁面的網址
pm.status_path = /phpfpm_status
# 為單個請求提供服務的逾時,之後工作程序将處理該請求被清理
request_terminate_timeout = 30s
# 能打開的最大檔案描述符
rlimit_files = 4096      

轉載于:https://www.cnblogs.com/xuweiqiang/p/10844249.html

繼續閱讀