function peer_event()
{
    global $connection, $settings;
    require_once __DIR__ . '/once.db.connect.php';
    require_once __DIR__ . '/function.mysqli.fetch.once.php';
    $peer = mysqli_fetch_once('SELECT * FROM `' . $settings['db_prefix'] . 'peers` ' . 'WHERE `info_hash`=\'' . $_GET['info_hash'] . '\' AND `peer_id`=\'' . $_GET['peer_id'] . '\'');
    // IF Event
    if (isset($_GET['event'])) {
        // IF Peer Exited
        if ($_GET['event'] == 'stopped') {
            if ($peer) {
                require_once __DIR__ . '/function.peer.delete.php';
                peer_delete();
                // HOOK PEER DELETE
                if (is_readable(__DIR__ . '/hook.peer.delete.php')) {
                    include __DIR__ . '/hook.peer.delete.php';
                }
            }
            exit;
            // END IF Peer Exited
            // IF Peer Completed
        } else {
            if ($_GET['event'] == 'completed') {
                // Force Seeding Status
                $settings['seeding'] = 1;
                // Increment downloads
                require_once __DIR__ . '/function.peer.completed.php';
                peer_completed();
                // HOOK DOWNLOAD COMPLETE
                if (is_readable(__DIR__ . '/hook.download.complete.php')) {
                    include __DIR__ . '/hook.download.complete.php';
                }
            }
        }
        // END IF Peer Completed
    }
    // END IF Event
    // IF Any Change
    if (!$peer || $peer['ip'] != $_GET['ip'] || $peer['port'] != $_GET['port'] || $peer['state'] != $settings['seeding']) {
        require_once __DIR__ . '/function.peer.new.php';
        peer_new();
        // HOOK PEER NEW/CHANGE
        if (is_readable(__DIR__ . '/hook.peer.change.php')) {
            include __DIR__ . '/hook.peer.change.php';
        }
        // END Any Change
        // IF Unchanged
    } else {
        require_once __DIR__ . '/function.peer.access.php';
        peer_access();
        // HOOK PEER ACCESS
        if (is_readable(__DIR__ . '/hook.peer.access.php')) {
            include __DIR__ . '/hook.peer.access.php';
        }
    }
    // END IF Unchanged
}
<?php

require_once $settings['functions'] . 'function.peer.delete.php';
require_once $settings['functions'] . 'function.mysqli.fetch.once.php';
$insert = 'INSERT INTO `' . $settings['db_prefix'] . 'peers` ( `info_hash`, `peer_id` ) VALUES ( \'__TEST_1__\', \'__TEST_1__\' );';
mysqli_query($connection, $insert);
$peer['info_hash'] = '__TEST_1__';
$peer['peer_id'] = '__TEST_1__';
peer_delete($connection, $settings, $peer);
$select = 'SELECT * FROM `' . $settings['db_prefix'] . 'peers` WHERE `info_hash` = \'__TEST_1__\' AND `peer_id` = \'__TEST_1__\';';
$result = mysqli_fetch_once($connection, $select);
$delete = 'DELETE FROM `' . $settings['db_prefix'] . 'peers` WHERE `info_hash` LIKE \'__TEST_%\';';
mysqli_query($connection, $delete);
if ($result) {
    echo 'Peer does not appear to have been deleted.' . PHP_EOL;
    $failure = true;
}