diff options
| -rw-r--r-- | index.php | 10 | ||||
| -rw-r--r-- | redis.php | 18 |
2 files changed, 27 insertions, 1 deletions
@@ -103,6 +103,9 @@ a { <?php if ( $set ){ function getInfo($url, $customHeader = array()){ + + require 'redis.php'; + $agent = "Retrieve HTTP headers online. v0.1"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -124,6 +127,10 @@ if ( $set ){ $host = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $result = array($request, $header, $host); + + # redis. remove this line if no redis + $redis->set( $key, serialize($result), 60 ); + return $result; } $header_info = getInfo($_REQUEST['url'], $_REQUEST['header']); @@ -148,6 +155,7 @@ Host: "<u><?php echo strtolower(htmlentities($header_info[2])); ?></u>"</pre></h echo "</pre>"; } ?> + <p>Entries are cached for 60 seconds.</p> <?php } else { ?> @@ -198,6 +206,7 @@ Host: "<u><?php echo strtolower(htmlentities($header_info[2])); ?></u>"</pre></h </fieldset> </form> + <?php } ?> @@ -213,7 +222,6 @@ Host: "<u><?php echo strtolower(htmlentities($header_info[2])); ?></u>"</pre></h </div> </div> </div> -<script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <script> //window.onload = function(){ diff --git a/redis.php b/redis.php new file mode 100644 index 0000000..36e0d98 --- /dev/null +++ b/redis.php @@ -0,0 +1,18 @@ +<?php + +$redis = new Redis(); +$redis ->connect("/var/run/redis/redis.sock"); +$redis->ping(); +$redis->select(9); + +$key = md5( $url . serialize($customHeader) ); + +if( $redis->exists( $key ) ){ + return unserialize( $redis->get( $key ) ); +} + +/* +if ( $setCache ){ + $redis->set( $key, serialize($result), 60 ); +} +*/ |
