<?php

$db = new mysqli('localhost', 'root', '5z#JaL');
$db->select_db('crm');

$docs = $db->query("SELECT id, document_revision_id FROM documents WHERE deleted = 0 AND document_revision_id != '' AND document_revision_id IS NOT NULL");

// loop docs query result

$notExists = 0;
$exists = 0;
while ($doc = $docs->fetch_assoc()) {
    $file = '/var/www/html/crm/upload/' . $doc['document_revision_id'];
    if (file_exists($file)) {
        //echo $doc['id'] . ' ' . $doc['document_revision_id'] .' EXISTS '. PHP_EOL;
        $exists++;
    } else {
        echo $doc['id'] . ' ' . $doc['document_revision_id'] .' NOT EXISTS '. PHP_EOL;
        $notExists++;
    }
}
echo 'Not exists: ' . $notExists . PHP_EOL;
echo 'Exists: ' . $exists . PHP_EOL;