‘Web Tools’ Category
» posted on Thursday, August 27th, 2009 at 3:16pm by Dan
Cloud Hosting Providers
I’ve had some experience trying out different cloud hosts and I’d just like to make a list of providers here:
post a comment | filed under Web Tools
» posted on Monday, August 24th, 2009 at 7:22pm by Dan
PHP File-System Cache
I’m just sharing a couple of functions I created a while back to cache some resource-intensive processed dada for quick and easy access. This is pretty ideal for large amounts of data and it’s very simple to set up. The beauty of this is that you can store just about any data type – it doesn’t have to be a string.
Just setup the cache directory to have proper read/write permissions (preferably in a non-accessible from web directory). Then use the two functions.
Example usage:
1 2 3 4 5 6 7 8 9 | // The 2nd argument, $hours is how long to retain data before getting new $contents = get_cache('TEST_KEY', 24); if ($contents === false) { // This is where you'd get data from an API, DB or whatever $contents = 'Just some example contents'; set_cache('TEST_KEY', $contents); } echo $contents; } |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 | define('CACHE_DIR', 'cache/'); // Include trailing slash function get_cache($key, $hours) { $file = CACHE_DIR . md5($key) . '.cache'; if (!file_exists($file) || filemtime($file) < time() - $hours * 3600) return false; return unserialize(file_get_contents($file)); } function set_cache($key, $value) { $file = CACHE_DIR . md5($key) . '.cache'; file_put_contents($file, serialize($value)); } |
post a comment | filed under Code · Web Tools
» posted on Wednesday, June 10th, 2009 at 1:20am by Dan
ASP File_Get_Contents and File_Put_Contents
As I’ve become more of a PHP developer than an ASP developer, one thing I’ve noticed is that it is 10x easier to read/write text files with PHP. Simple use file_get_contents() and be done. ASP isn’t so nice. But it can be done, so I’m creating those for simplicity here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <% Function File_Get_Contents(strFile) Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFile, 1) File_Get_Contents = objFile.ReadAll() Set objFile = Nothing Set objFSO = Nothing End Function Function File_Put_Contents(strFile, strContents, blnAppend) If blnAppend Then intMode = 8 Else intMode = 2 End If Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFile, intMode, True) objFile.Write(strContents) Set objFile = Nothing Set objFSO = Nothing End Function %> |
Of course this file_get_contents doesn’t support remote URLs, but it can easily be added.
post a comment | filed under Web Tools | tags: asp



![[del.icio.us]](http://www.randomtools.net/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.randomtools.net/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://www.randomtools.net/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://www.randomtools.net/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://www.randomtools.net/wp-content/plugins/bookmarkify/myspace.png)
![[Reddit]](http://www.randomtools.net/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://www.randomtools.net/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://www.randomtools.net/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://www.randomtools.net/wp-content/plugins/bookmarkify/technorati.png)
![[Windows Live]](http://www.randomtools.net/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.randomtools.net/wp-content/plugins/bookmarkify/yahoo.png)