ตัวอย่าง Code PHP Grab Process ID จาก Linux Sever

By | 07/04/2018
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function isRunning($dm) {
    $cmd = "ps o pid,command -C php";
    $res = shell_exec($cmd);
    $expl = array();
    /*
    $res=trim("  PID COMMAND
    21682 /usr/local/bin/php -f program.php key1
    23380 /usr/local/bin/php -f program.php key2
    23473 /usr/local/bin/php -f program.php key3");
    */

    $expl = explode("\n",$res);
    foreach ($expl as $pss) {
        /*
        echo '<pre>';
        print_r($expl = explode(" ",$pss);
        echo '</pre>';
        */

        $expl = explode(" ",trim($pss));
        if($expl[4]==$dm) {
            $return = trim($expl[0]);
        }
    }
    if($return == "") {
        $return = "off";
    }
    return $return;
}

ใส่ความเห็น