phpopencart

vqmod generate cache for all files


Is it possible to generate all of the vqcache files for vqmod at once?

I would like to run this script once when the server has a low load and it would go through all of the qmod files and apply all of the changes, ready and waiting for the high load.

This would also alert me of any vqmod errors, instead of having to wait for them to occur.

E,g when I install/uninstall the extension I also need to uninstall the vqmod extensions with:

/**
 * install/uninstall vqmod files for extension
 *
 * @param string $action = install/uninstall
 */
private function _vqmodAction($action){

    $vqmod_path = str_replace("system", "vqmod", DIR_SYSTEM);

    // Clear vqmod cache
    $files = glob($vqmod_path.'vqcache/vq*');
    if ($files) {
        foreach ($files as $file) {
            if (file_exists($file)) {
                @unlink($file);
                clearstatcache();
            }
        }
    }

    // Force vqmod to re-generate cache
    global $vqmod;
    $vqmod->modCheck(DIR_SYSTEM . 'startup.php');

    // Re-name vqmod files
    $vqmod_xml_path = $vqmod_path . "xml/";
    $vqmod_files = array('file', 'file_languages', 'file_admin');
    foreach($vqmod_files as $filename){
        if($action == "uninstall"){
            $from = '.xml';
            $to = '.xml_';
        } else {
            $from = '.xml_';
            $to = '.xml';
        }
        if (file_exists($vqmod_xml_path.$filename.$from)) {
            rename($vqmod_xml_path.$filename.$from, $vqmod_xml_path.$filename.$to);
        }
    }

    return true;
}

The reason for modCheck the startup.php is because this includes required files and changes made via vqmod. Is this the correct way to handle this situation?


Solution

  • You can do this manually with an external program like httrack . When you crawly your site with a similar application all pages will be visited before your site visitors do. So all cache files will be created.

    http://www.httrack.com/

    Do you need to repeat this occasionally ? If so you need to make a self crawling / or cache maker script.