1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-01 22:00:31 +02:00

more test

This commit is contained in:
Mikael Roos
2016-08-08 10:39:11 +02:00
parent b1d0cb1506
commit 72c04632b8
13 changed files with 120 additions and 23 deletions

View File

@@ -92,6 +92,10 @@ class CFastTrackCache
$this->filename = md5($queryAsString); $this->filename = md5($queryAsString);
if (CIMAGE_DEBUG) {
$this->container["query-string"] = $queryAsString;
}
return $this->filename; return $this->filename;
} }
@@ -215,6 +219,9 @@ class CFastTrackCache
if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])
&& strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $item["last-modified"]) { && strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $item["last-modified"]) {
header("HTTP/1.0 304 Not Modified"); header("HTTP/1.0 304 Not Modified");
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 304");
}
exit; exit;
} }
@@ -222,6 +229,9 @@ class CFastTrackCache
header($value); header($value);
} }
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 200");
}
readfile($item["source"]); readfile($item["source"]);
exit; exit;
} }

View File

@@ -2621,6 +2621,9 @@ class CImage
} }
header("HTTP/1.0 304 Not Modified"); header("HTTP/1.0 304 Not Modified");
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 304");
}
} else { } else {
@@ -2651,6 +2654,9 @@ class CImage
$this->fastTrackCache->setSource($file); $this->fastTrackCache->setSource($file);
$this->fastTrackCache->writeToCache(); $this->fastTrackCache->writeToCache();
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 200");
}
readfile($file); readfile($file);
} }

View File

@@ -14,6 +14,8 @@ v0.7.13 (2016-08-08)
* Added `imgf.php` as shortcut to check for fast cache, before loading `img.php` as usual. * Added `imgf.php` as shortcut to check for fast cache, before loading `img.php` as usual.
* Created `defines.php` and moved definition av version there. * Created `defines.php` and moved definition av version there.
* Fixed images in README, #148. * Fixed images in README, #148.
* Initiated dependency injection to `CImage`, class names can be set in config file and will be injected to `CImage` from `img.php`. Not implemented for all classes. #151.
* Enabled debug mode to make it easeier to trace what actually happens while processing the image, #150.
v0.7.12 (2016-06-01) v0.7.12 (2016-06-01)

View File

@@ -3,8 +3,8 @@
* Autoloader for CImage and related class files. * Autoloader for CImage and related class files.
* *
*/ */
require __DIR__ . "/defines.php"; require_once __DIR__ . "/defines.php";
require __DIR__ . "/functions.php"; require_once __DIR__ . "/functions.php";

View File

@@ -35,7 +35,7 @@
"CRemoteImage.php", "CRemoteImage.php",
"CWhitelist.php", "CWhitelist.php",
"CAsciiArt.php", "CAsciiArt.php",
"CCache.php" "CCache.php",
"CFastTrackCache.php" "CFastTrackCache.php"
] ]
} }

View File

@@ -4,3 +4,9 @@ define("CIMAGE_VERSION", "v0.7.13 (2016-08-08)");
// For CRemoteImage // For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION); define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
// Change to true to enable debug mode which logs additional information
// to file. Only use for test and development.
define("CIMAGE_DEBUG", true);
define("CIMAGE_DEBUG_FILE", "/tmp/cimage");
//define("CIMAGE_DEBUG", false);

View File

@@ -14,15 +14,15 @@
*/ */
function trace($msg) function trace($msg)
{ {
$file = "/tmp/cimage"; $file = CIMAGE_DEBUG_FILE;
if (!is_writable($file)) { if (!is_writable($file)) {
die("Using trace without a writable logfile. Create the file '$file' and make it writable for the web server."); die("Using trace without a writable logfile. Create the file '$file' and make it writable for the web server.");
} }
$msg .= ":" . count(get_included_files()); $details = ":" . (string) round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 6) . "ms";
$msg .= ":" . round(memory_get_peak_usage()/1024/1024, 3) . "MB"; $details .= ":" . round(memory_get_peak_usage()/1024/1024, 3) . "MB";
$msg .= ":" . (string) round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 6) . "ms"; $details .= ":" . count(get_included_files());
file_put_contents($file, "$msg\n", FILE_APPEND); file_put_contents($file, "$details:$msg\n", FILE_APPEND);
} }

View File

@@ -247,6 +247,9 @@ $img->injectDependency("fastTrackCache", $ftc);
* in cache. * in cache.
*/ */
if ($useCache && $allowFastTrackCache) { if ($useCache && $allowFastTrackCache) {
if (CIMAGE_DEBUG) {
trace("img.php fast track cache enabled and used");
}
$ftc->output(); $ftc->output();
} }

View File

@@ -66,7 +66,9 @@ return array(
/** /**
* Class names to use, to ease dependency injection. * Class names to use, to ease dependency injection. You can change Class
* name if you want to use your own class instead. This is a way to extend
* the codebase.
* *
* Default values: * Default values:
* CImage: CImage * CImage: CImage

View File

@@ -43,6 +43,12 @@ define("CIMAGE_VERSION", "v0.7.13 (2016-08-08)");
// For CRemoteImage // For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION); define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
// Change to true to enable debug mode which logs additional information
// to file. Only use for test and development.
define("CIMAGE_DEBUG", true);
define("CIMAGE_DEBUG_FILE", "/tmp/cimage");
//define("CIMAGE_DEBUG", false);
/** /**
@@ -60,15 +66,15 @@ define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
*/ */
function trace($msg) function trace($msg)
{ {
$file = "/tmp/cimage"; $file = CIMAGE_DEBUG_FILE;
if (!is_writable($file)) { if (!is_writable($file)) {
die("Using trace without a writable logfile. Create the file '$file' and make it writable for the web server."); die("Using trace without a writable logfile. Create the file '$file' and make it writable for the web server.");
} }
$msg .= ":" . count(get_included_files()); $details = ":" . (string) round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 6) . "ms";
$msg .= ":" . round(memory_get_peak_usage()/1024/1024, 3) . "MB"; $details .= ":" . round(memory_get_peak_usage()/1024/1024, 3) . "MB";
$msg .= ":" . (string) round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 6) . "ms"; $details .= ":" . count(get_included_files());
file_put_contents($file, "$msg\n", FILE_APPEND); file_put_contents($file, "$details:$msg\n", FILE_APPEND);
} }
@@ -3720,6 +3726,9 @@ class CImage
} }
header("HTTP/1.0 304 Not Modified"); header("HTTP/1.0 304 Not Modified");
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 304");
}
} else { } else {
@@ -3750,6 +3759,9 @@ class CImage
$this->fastTrackCache->setSource($file); $this->fastTrackCache->setSource($file);
$this->fastTrackCache->writeToCache(); $this->fastTrackCache->writeToCache();
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 200");
}
readfile($file); readfile($file);
} }
@@ -4136,6 +4148,10 @@ class CFastTrackCache
$this->filename = md5($queryAsString); $this->filename = md5($queryAsString);
if (CIMAGE_DEBUG) {
$this->container["query-string"] = $queryAsString;
}
return $this->filename; return $this->filename;
} }
@@ -4259,6 +4275,9 @@ class CFastTrackCache
if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])
&& strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $item["last-modified"]) { && strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $item["last-modified"]) {
header("HTTP/1.0 304 Not Modified"); header("HTTP/1.0 304 Not Modified");
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 304");
}
exit; exit;
} }
@@ -4266,6 +4285,9 @@ class CFastTrackCache
header($value); header($value);
} }
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 200");
}
readfile($item["source"]); readfile($item["source"]);
exit; exit;
} }
@@ -4521,6 +4543,9 @@ $img->injectDependency("fastTrackCache", $ftc);
* in cache. * in cache.
*/ */
if ($useCache && $allowFastTrackCache) { if ($useCache && $allowFastTrackCache) {
if (CIMAGE_DEBUG) {
trace("img.php fast track cache enabled and used");
}
$ftc->output(); $ftc->output();
} }

View File

@@ -3,7 +3,6 @@
* Fast track cache, read entries from the cache before processing image * Fast track cache, read entries from the cache before processing image
* the ordinary way. * the ordinary way.
*/ */
// Load the config file or use defaults // Load the config file or use defaults
$configFile = __DIR__ $configFile = __DIR__
. "/" . "/"
@@ -14,10 +13,23 @@ if (is_file($configFile) && is_readable($configFile)) {
$config = require $configFile; $config = require $configFile;
} elseif (!isset($config)) { } elseif (!isset($config)) {
$config = array( $config = array(
"debug" => false,
"autoloader" => __DIR__ . "/../autoload.php",
"cache_path" => __DIR__ . "/../cache/", "cache_path" => __DIR__ . "/../cache/",
); );
} }
// Debug mode needs additional functions
if (CIMAGE_DEBUG) {
require $config["autoloader"];
}
// Cache path must be valid
$cacheIsReadable = is_dir($config["cache_path"]) && is_readable($config["cache_path"]);
if (!$cacheIsReadable) {
die("imgf.php: Cache is not readable, check path in configfile.");
}
// Prepare to check if fast cache should be used // Prepare to check if fast cache should be used
$cachePath = $config["cache_path"] . "/fasttrack"; $cachePath = $config["cache_path"] . "/fasttrack";
$query = $_GET; $query = $_GET;
@@ -49,6 +61,9 @@ if ($useCache && is_readable($filename)) {
if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])
&& strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $item["last-modified"]) { && strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $item["last-modified"]) {
header("HTTP/1.0 304 Not Modified"); header("HTTP/1.0 304 Not Modified");
if (CIMAGE_DEBUG) {
trace("imgf 304");
}
exit; exit;
} }
@@ -56,6 +71,9 @@ if ($useCache && is_readable($filename)) {
header($value); header($value);
} }
if (CIMAGE_DEBUG) {
trace("imgf 200");
}
readfile($item["source"]); readfile($item["source"]);
exit; exit;
} }

View File

@@ -43,6 +43,12 @@ define("CIMAGE_VERSION", "v0.7.13 (2016-08-08)");
// For CRemoteImage // For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION); define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
// Change to true to enable debug mode which logs additional information
// to file. Only use for test and development.
define("CIMAGE_DEBUG", true);
define("CIMAGE_DEBUG_FILE", "/tmp/cimage");
//define("CIMAGE_DEBUG", false);
/** /**
@@ -60,15 +66,15 @@ define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
*/ */
function trace($msg) function trace($msg)
{ {
$file = "/tmp/cimage"; $file = CIMAGE_DEBUG_FILE;
if (!is_writable($file)) { if (!is_writable($file)) {
die("Using trace without a writable logfile. Create the file '$file' and make it writable for the web server."); die("Using trace without a writable logfile. Create the file '$file' and make it writable for the web server.");
} }
$msg .= ":" . count(get_included_files()); $details = ":" . (string) round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 6) . "ms";
$msg .= ":" . round(memory_get_peak_usage()/1024/1024, 3) . "MB"; $details .= ":" . round(memory_get_peak_usage()/1024/1024, 3) . "MB";
$msg .= ":" . (string) round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 6) . "ms"; $details .= ":" . count(get_included_files());
file_put_contents($file, "$msg\n", FILE_APPEND); file_put_contents($file, "$details:$msg\n", FILE_APPEND);
} }
@@ -3720,6 +3726,9 @@ class CImage
} }
header("HTTP/1.0 304 Not Modified"); header("HTTP/1.0 304 Not Modified");
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 304");
}
} else { } else {
@@ -3750,6 +3759,9 @@ class CImage
$this->fastTrackCache->setSource($file); $this->fastTrackCache->setSource($file);
$this->fastTrackCache->writeToCache(); $this->fastTrackCache->writeToCache();
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 200");
}
readfile($file); readfile($file);
} }
@@ -4136,6 +4148,10 @@ class CFastTrackCache
$this->filename = md5($queryAsString); $this->filename = md5($queryAsString);
if (CIMAGE_DEBUG) {
$this->container["query-string"] = $queryAsString;
}
return $this->filename; return $this->filename;
} }
@@ -4259,6 +4275,9 @@ class CFastTrackCache
if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])
&& strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $item["last-modified"]) { && strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $item["last-modified"]) {
header("HTTP/1.0 304 Not Modified"); header("HTTP/1.0 304 Not Modified");
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 304");
}
exit; exit;
} }
@@ -4266,6 +4285,9 @@ class CFastTrackCache
header($value); header($value);
} }
if (CIMAGE_DEBUG) {
trace(__CLASS__ . " 200");
}
readfile($item["source"]); readfile($item["source"]);
exit; exit;
} }
@@ -4521,6 +4543,9 @@ $img->injectDependency("fastTrackCache", $ftc);
* in cache. * in cache.
*/ */
if ($useCache && $allowFastTrackCache) { if ($useCache && $allowFastTrackCache) {
if (CIMAGE_DEBUG) {
trace("img.php fast track cache enabled and used");
}
$ftc->output(); $ftc->output();
} }

File diff suppressed because one or more lines are too long