HEX
Server: Apache
System: Linux 136-243-153-58.cprapid.com 4.18.0-553.81.1.el8_10.x86_64 #1 SMP Mon Oct 27 11:29:19 EDT 2025 x86_64
User: mytest (1001)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/mytest/.trash/clear_cache.php.61
<?php
/**
 * Cache Clearing Utility
 * Clears all possible PHP cache types including OPcache, APCu, file cache, and session data
 * 
 * Usage: Access via browser at https://yourdomain.com/clear_cache.php
 * For security, this file should be removed after use or protected with authentication
 */

header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
    <title>Cache Clearing Utility</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 40px; background: #f5f5f5; }
        .container { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); max-width: 800px; margin: 0 auto; }
        h1 { color: #333; border-bottom: 2px solid #0a3758; padding-bottom: 10px; }
        .success { color: #28a745; padding: 10px; background: #d4edda; border: 1px solid #c3e6cb; border-radius: 4px; margin: 10px 0; }
        .error { color: #dc3545; padding: 10px; background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px; margin: 10px 0; }
        .info { color: #0c5460; padding: 10px; background: #d1ecf1; border: 1px solid #bee5eb; border-radius: 4px; margin: 10px 0; }
        .section { margin: 20px 0; padding: 15px; background: #f8f9fa; border-left: 4px solid #0a3758; }
        .section h3 { margin-top: 0; color: #0a3758; }
        ul { line-height: 1.8; }
        .timestamp { font-size: 0.9em; color: #666; margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd; }
    </style>
</head>
<body>
    <div class="container">
        <h1>๐Ÿงน Cache Clearing Utility</h1>
        <p>This utility clears all possible cache types in your PHP application.</p>
        
        <?php
        $results = [];
        $errors = [];
        
        // 1. Clear OPcache (PHP bytecode cache)
        if (function_exists('opcache_reset')) {
            if (opcache_reset()) {
                $results[] = "โœ… OPcache cleared successfully";
            } else {
                $errors[] = "โŒ Failed to clear OPcache";
            }
        } else {
            $results[] = "โ„น๏ธ OPcache not available or not enabled";
        }
        
        // 2. Clear APCu cache (user cache)
        if (function_exists('apcu_clear_cache')) {
            if (apcu_clear_cache()) {
                $results[] = "โœ… APCu cache cleared successfully";
            } else {
                $errors[] = "โŒ Failed to clear APCu cache";
            }
        } else {
            $results[] = "โ„น๏ธ APCu not available or not enabled";
        }
        
        // 3. Clear Realpath cache
        clearstatcache(true);
        $results[] = "โœ… Realpath cache cleared";
        
        // 4. Clear session data (current session only)
        if (session_status() === PHP_SESSION_NONE) {
            session_start();
        }
        $_SESSION = [];
        if (ini_get("session.use_cookies")) {
            $params = session_get_cookie_params();
            setcookie(session_name(), '', time() - 42000,
                $params["path"], $params["domain"],
                $params["secure"], $params["httponly"]
            );
        }
        session_destroy();
        $results[] = "โœ… Session data cleared";
        
        // 5. Clear file-based cache directories (if they exist)
        $cacheDirs = [
            __DIR__ . '/cache',
            __DIR__ . '/tmp',
            __DIR__ . '/storage/cache',
            __DIR__ . '/var/cache',
            __DIR__ . '/data/cache'
        ];
        
        $filesDeleted = 0;
        foreach ($cacheDirs as $dir) {
            if (is_dir($dir)) {
                $files = glob($dir . '/*');
                foreach ($files as $file) {
                    if (is_file($file) && basename($file) !== '.gitkeep') {
                        if (unlink($file)) {
                            $filesDeleted++;
                        }
                    }
                }
            }
        }
        
        if ($filesDeleted > 0) {
            $results[] = "โœ… Deleted $filesDeleted cache file(s)";
        } else {
            $results[] = "โ„น๏ธ No cache files found to delete";
        }
        
        // 6. Clear output buffers
        while (ob_get_level()) {
            ob_end_clean();
        }
        $results[] = "โœ… Output buffers cleared";
        
        // 7. Force browser cache refresh headers
        header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Pragma: no-cache");
        header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
        $results[] = "โœ… Browser cache headers set";
        
        // Display results
        if (!empty($results)) {
            echo '<div class="section">';
            echo '<h3>โœจ Cache Clearing Results</h3>';
            echo '<ul>';
            foreach ($results as $result) {
                echo '<li>' . htmlspecialchars($result) . '</li>';
            }
            echo '</ul>';
            echo '</div>';
        }
        
        if (!empty($errors)) {
            echo '<div class="section">';
            echo '<h3>โš ๏ธ Errors Encountered</h3>';
            echo '<ul>';
            foreach ($errors as $error) {
                echo '<li class="error">' . htmlspecialchars($error) . '</li>';
            }
            echo '</ul>';
            echo '</div>';
        }
        
        // PHP Info
        echo '<div class="section">';
        echo '<h3>๐Ÿ“Š PHP Cache Configuration</h3>';
        echo '<ul>';
        echo '<li><strong>OPcache Enabled:</strong> ' . (function_exists('opcache_get_status') && opcache_get_status() ? 'Yes' : 'No') . '</li>';
        echo '<li><strong>APCu Enabled:</strong> ' . (function_exists('apcu_cache_info') ? 'Yes' : 'No') . '</li>';
        echo '<li><strong>PHP Version:</strong> ' . PHP_VERSION . '</li>';
        echo '<li><strong>Server Time:</strong> ' . date('Y-m-d H:i:s T') . '</li>';
        echo '</ul>';
        echo '</div>';
        
        // Instructions
        echo '<div class="info">';
        echo '<h3>๐Ÿ“ Next Steps</h3>';
        echo '<p><strong>To ensure complete cache clearing:</strong></p>';
        echo '<ol>';
        echo '<li>Hard refresh your browser (Ctrl+Shift+R or Cmd+Shift+R)</li>';
        echo '<li>Clear your browser cache and cookies</li>';
        echo '<li>If using a CDN or proxy (Cloudflare, etc.), purge the CDN cache</li>';
        echo '<li>Restart your web server if possible (Apache/Nginx)</li>';
        echo '<li><strong>For security:</strong> Delete this file after use or protect it with authentication</li>';
        echo '</ol>';
        echo '</div>';
        ?>
        
        <div class="timestamp">
            <strong>Cache cleared at:</strong> <?php echo date('Y-m-d H:i:s T'); ?>
        </div>
    </div>
</body>
</html>