DATA/UPBIT/daemon/target/db_record.php
<?php
// =============================================================
// db_record.php - 데몬 상태 기록 파일
// =============================================================

function record_daemon($db_upbit, $status = 'RUNNING', $memo = '') {
    static $DAEMON_ID  = null;
    static $start_time = null;
    static $pid        = null;
    static $ip         = null;

    if ($DAEMON_ID === null) {
        $DAEMON_ID  = pathinfo($_SERVER['SCRIPT_FILENAME'], PATHINFO_FILENAME);
        $start_time = date('Y-m-d H:i:s');
        $pid        = getmypid();
        $ip         = gethostbyname(gethostname());
    }

    if (!is_object($db_upbit)) return;

    try {
        $sql = "INSERT INTO daemon_record 
                    (d_id, d_category, d_pid, d_status, d_heartbeat, d_ip, d_start_time, d_memo)
                VALUES 
                    (:d_id, 'UPBIT', :d_pid, :d_status, NOW(), :d_ip, :d_start_time, :d_memo)
                ON DUPLICATE KEY UPDATE
                    d_pid       = :d_pid2,
                    d_status    = :d_status2,
                    d_heartbeat = NOW(),
                    d_ip        = :d_ip2,
                    d_memo      = :d_memo2";

        $stmt = $db_upbit->prepare($sql);
        $stmt->execute([
            ':d_id'         => $DAEMON_ID,
            ':d_pid'        => $pid,
            ':d_status'     => $status,
            ':d_ip'         => $ip,
            ':d_start_time' => $start_time,
            ':d_memo'       => $memo,
            ':d_pid2'       => $pid,
            ':d_status2'    => $status,
            ':d_ip2'        => $ip,
            ':d_memo2'      => $memo,
        ]);

    } catch (Throwable $e) {
        return;
    }
}
?>