Example #1
0
    $retries = 0;
    //if autogal.lock there probably
    //another instance of the script
    //running. Give it some seconds
    //to finish
    while (file_exists('../../autogal.lock') && $retries < Config::max_retries) {
        //echo 'sleeping';
        sleep(1);
        $retries++;
    }
    //create a lock file so two
    //instances of the script don't
    //try to rebuild the galleries at
    //the same time
    try {
        $filelock = fopen('../../autogal.lock', 'w');
    } catch (Exception $e) {
        throw new Exeption('can\'t create autogal.lock');
    }
    $myDatabase = new Database();
    $myGenerator = new HTMLGenerator();
    $myDatabase->generateFromFile(Config::getDirURL());
    $myGenerator->generatePages($myDatabase->getCategories(), $myDatabase->getCollection());
    //Open autogal.lastmod and write the new hash of dir.txt
    $lastmod = fopen('../../autogal.lastmod', 'w');
    fwrite($lastmod, $dirhash);
    fclose($lastmod);
    fclose($filelock);
}
//Remove the lock
unlink('../../autogal.lock');