OpenSencillo  2015.002
file.php File Reference

Go to the source code of this file.

Functions

 quickcache_restore ()
 quickcache_write ($gzdata, $datasize, $datacrc)
 quickcache_do_gc ()
 quickcache_do_start ()
 quickcache_do_end ()
 quickcache_fileread ($filename)
 quickcache_filewrite ($filename, $data)

Function Documentation

Definition at line 138 of file file.php.

                             {
  // Add additional code you might require
}

Definition at line 93 of file file.php.

                            {
  $dp=opendir($GLOBALS["QUICKCACHE_DIR"]);

  // Can we access directory ?
  if (!$dp)
  {
      quickcache_debug("Error opening ". $GLOBALS["QUICKCACHE_DIR"] ." for garbage-collection");
  }

  while (!(($de=readdir($dp))===FALSE))
  {
    // To get around strange php-strpos, add additional char
    // Only read quickcache-files.
    if (strpos("x$de", $GLOBALS["QUICKCACHE_FILEPREFIX"])==1) {
      $filename=$GLOBALS["QUICKCACHE_DIR"] . "/" . $de;
      // read file and unserializes the data
      $cachedata=unserialize(quickcache_fileread($filename));

      // Check data in array.
      if (is_array($cachedata)) {
        if ($cachedata["quickcache_expire"]!="0" && $cachedata["quickcache_expire"]<=time()) {
          // Unlink file, we do not need to get a lock
          $deleted = @unlink($filename);
          if ($deleted) {
              quickcache_debug("Successfully unlinked $filename");
          } else {
            quickcache_debug("Failed to unlink $filename");
          }
        }
      }
    }
  }
}

Definition at line 130 of file file.php.

                               {
  // Add additional code you might require
}
quickcache_fileread ( filename)

Definition at line 143 of file file.php.

                                        {
  // php.net suggested I should use rb to make it work under Windows
  $fp=@fopen($filename, "rb");
  if (!$fp) {
    quickcache_debug("Failed to open for read of $filename");
    return NULL;
  }

  // Get a shared lock
  flock($fp, LOCK_SH);

  $buff="";
  // Be gentle, so read in 4k blocks
  while (($tmp=fread($fp, 4096))) {
    $buff.=$tmp;
  }

  // Release lock
  flock($fp, LOCK_UN);
  fclose($fp);
  // Return
  return $buff;
}
quickcache_filewrite ( filename,
data 
)

Definition at line 168 of file file.php.

                                                {
  $return = FALSE;
  // Lock file, ignore warnings as we might be creating this file
  $fpt = @fopen($filename, "rb");
  @flock($fpt, LOCK_EX);

  // php.net suggested I should use wb to make it work under Windows
  $fp=@fopen($filename, "wb+");
  if (!$fp) {
    // Strange! We are not able to write the file!
    quickcache_debug("Failed to open for write of $filename");
  } else {
    fwrite($fp, $data, strlen($data));
    fclose($fp);
    $return = TRUE;
  }

  // Release lock
  @flock($fpt, LOCK_UN);
  @fclose($fpt);
  // Return
  return $return;
}

Definition at line 33 of file file.php.

                              {
  // Construct filename
  $filename = $GLOBALS["QUICKCACHE_DIR"]."/".$GLOBALS["QUICKCACHE_FILEPREFIX"].$GLOBALS["quickcache_key"];

  // read file and unserialize the data
  $cachedata=unserialize(quickcache_fileread($filename));
  if (is_array($cachedata)) {
    // Only read cachefiles of my version
    if ($cachedata["quickcache_version"] == $GLOBALS["QUICKCACHE_VERSION"]) {
      if (($cachedata["quickcache_expire"] == "0") ||
        ($cachedata["quickcache_expire"] >= time()))
      {
        //Restore data
        $GLOBALS["quickcachedata_gzdata"]   = $cachedata["quickcachedata_gzdata"];
        $GLOBALS["quickcachedata_datasize"] = $cachedata["quickcachedata_datasize"];
        $GLOBALS["quickcachedata_datacrc"]  = $cachedata["quickcachedata_datacrc"];
        return TRUE;
      } else {
        quickcache_debug("Data in cachefile $filename has expired");
      }
    } else {
      // Invalid version of cache-file
      quickcache_debug("Invalid version of cache-file $filename");
    }
  } else {
    // Invalid cache-file
    quickcache_debug("Invalid content of cache-file $filename");
  }

  return FALSE;
}
quickcache_write ( gzdata,
datasize,
datacrc 
)

Definition at line 68 of file file.php.

                                                        {
  // Construct filename
  $filename = $GLOBALS["QUICKCACHE_DIR"]."/".$GLOBALS["QUICKCACHE_FILEPREFIX"].$GLOBALS["quickcache_key"];

  // Create and fill cachedata-array
  $cachedata = array();
  $cachedata["quickcache_version"] = $GLOBALS["QUICKCACHE_VERSION"];
  $cachedata["quickcache_expire"] = ($GLOBALS["QUICKCACHE_TIME"] > 0) ?
                                      time() + $GLOBALS["QUICKCACHE_TIME"] :
                                      0;
  $cachedata["quickcachedata_gzdata"] = $gzdata;
  $cachedata["quickcachedata_datasize"] = $datasize;
  $cachedata["quickcachedata_datacrc"] = $datacrc;

  // And write the data
  if (quickcache_filewrite($filename, serialize($cachedata))) {
    quickcache_debug("Successfully wrote cachefile $filename");
  } else {
    quickcache_debug("Unable to write cachefile $filename");
  }
}
 All Data Structures Files Functions Variables