diff options
author | Christian Schneider | 2006-12-12 13:38:57 +0000 |
---|---|---|
committer | Christian Schneider | 2006-12-12 13:38:57 +0000 |
commit | fd9171e0df775da9c4a3ea22e8f95ec75d3b3897 (patch) | |
tree | 53e93e18851d1c780f73e5464b89b1aad87f598c /urlcache/urlcache.class | |
parent | ee2fcb5bbc9b9db282a4668c50d87447b2114886 (diff) | |
download | itools-fd9171e0df775da9c4a3ea22e8f95ec75d3b3897.tar.gz itools-fd9171e0df775da9c4a3ea22e8f95ec75d3b3897.tar.bz2 itools-fd9171e0df775da9c4a3ea22e8f95ec75d3b3897.zip |
Merged revisions 13944-15067 via svnmerge from
svn+ssh://rdc.rim.ch/rdc/svn/itools/devel-redesign
........
r13945 | weber | 2006-10-26 16:13:44 +0200 (Thu, 26 Oct 2006) | 2 lines
omit null attributes, true means add name only. select() supports optgroups
........
r13946 | weber | 2006-10-26 16:22:42 +0200 (Thu, 26 Oct 2006) | 2 lines
Removed cruft
........
r13989 | cschneid | 2006-10-27 18:32:11 +0200 (Fri, 27 Oct 2006) | 1 line
Removed more cruft
........
r13991 | cschneid | 2006-10-28 19:36:35 +0200 (Sat, 28 Oct 2006) | 1 line
Make adserver output xhtml compliant tags
........
r14093 | weber | 2006-11-06 17:13:23 +0100 (Mon, 06 Nov 2006) | 2 lines
title tag can be omitted completely
........
r14096 | weber | 2006-11-06 18:00:43 +0100 (Mon, 06 Nov 2006) | 2 lines
Q() doesn't encode newlines, tag() encodes newlines within attributes
........
r14135 | weber | 2006-11-09 02:30:03 +0100 (Thu, 09 Nov 2006) | 2 lines
Migrate DB to texts.php on the fly (this functionality will be removed later), use only statictext, not DB
........
r14164 | mueller | 2006-11-09 19:23:40 +0100 (Thu, 09 Nov 2006) | 1 line
disable empty options in select
........
r14194 | mueller | 2006-11-13 14:34:25 +0100 (Mon, 13 Nov 2006) | 1 line
imply choose() in show()
........
r14212 | weber | 2006-11-13 18:14:33 +0100 (Mon, 13 Nov 2006) | 2 lines
Debug output is left-aligned
........
r14231 | cschneid | 2006-11-14 17:09:32 +0100 (Tue, 14 Nov 2006) | 1 line
Load js files before dom is ready and prevent loops on static=
........
r14288 | cschneid | 2006-11-15 13:16:54 +0100 (Wed, 15 Nov 2006) | 1 line
More compact serialization of arrays
........
r14388 | weber | 2006-11-22 18:19:34 +0100 (Wed, 22 Nov 2006) | 2 lines
Add optional IE PNG fix to it_html::img()
........
r14442 | mueller | 2006-11-27 23:22:23 +0100 (Mon, 27 Nov 2006) | 1 line
correctly handle <option value="">
........
r14444 | cschneid | 2006-11-28 12:35:43 +0100 (Tue, 28 Nov 2006) | 1 line
Handle null separately to preserve 0 == '0'
........
r14450 | cschneid | 2006-11-28 15:36:45 +0100 (Tue, 28 Nov 2006) | 1 line
Style commit (mainly done to test commit-email)
........
r14451 | cschneid | 2006-11-28 15:44:49 +0100 (Tue, 28 Nov 2006) | 1 line
Test commit for commit-email
........
r14638 | cschneid | 2006-12-01 14:20:45 +0100 (Fri, 01 Dec 2006) | 1 line
Suppress warning in case src file was removed by race
........
r14970 | weber | 2006-12-09 03:07:22 +0100 (Sat, 09 Dec 2006) | 2 lines
Added the highly useful timerlog() method from searchlib to justify the supporting code in auto_append.php ;)
........
r14971 | weber | 2006-12-09 03:08:49 +0100 (Sat, 09 Dec 2006) | 2 lines
Added set(), made dump_php's return value more convincing
........
r14993 | cschneid | 2006-12-11 14:05:29 +0100 (Mon, 11 Dec 2006) | 1 line
Added itjs::send_headers() to send HTTP headers suitable for JSON data
........
r14997 | cschneid | 2006-12-11 14:28:52 +0100 (Mon, 11 Dec 2006) | 1 line
Set JSON expiration date for IE
........
r15057 | weber | 2006-12-12 14:02:43 +0100 (Tue, 12 Dec 2006) | 2 lines
documentation update
........
Diffstat (limited to 'urlcache/urlcache.class')
-rw-r--r-- | urlcache/urlcache.class | 217 |
1 files changed, 0 insertions, 217 deletions
diff --git a/urlcache/urlcache.class b/urlcache/urlcache.class deleted file mode 100644 index b058a1c..0000000 --- a/urlcache/urlcache.class +++ /dev/null @@ -1,217 +0,0 @@ -<?php -/* -** $Id$ -** -** Relog Internet Tools 3 Library ("ITOOLS3") -** -** it_urlcache.class - Interface to URL content cache in DB -** -** This class relies on a DB table with the following scheme: -** url CHAR(255) NOT NULL, -** updateinterval INT NOT NULL, -** lastupdate INT NOT NULL, -** nextupdate INT NOT NULL, -** contentmd5 CHAR(32) NOT NULL, -** content TEXT NOT NULL, -** PRIMARY KEY (url), -** KEY (nextupdate) -*/ - -/* PRIVATE */ -define("_IT_URLCACHE_DEFAULT_INTERVAL", 300); -define("_IT_URLCACHE_MAX_CONNECTIONS", 30); - -class it_urlcache extends it_db_record -{ - /* PRIVATE */ - var $default_interval = _IT_URLCACHE_DEFAULT_INTERVAL; - var $max_connections = _IT_URLCACHE_MAX_CONNECTIONS; - -function set_default_interval($default_interval) -{ - $this->default_interval = $default_interval; -} - - -function set_max_connections($max_connections) -{ - $this->max_connections = $max_connections; -} - - -/* - * Register an URL to be fetched by background process. - * Note: get() will return an empty string until the url is fetched for the - * first time - */ -function register($url) -{ - if (!$this->read($url)) - { - $tags = array("url" => $url, "updateinterval" => $this->default_interval); - $this->create($tags); - } -} - - -/* - * Removes the url from the cache. It won't be fetched again until register() - * is called again. - */ -function unregister($url) -{ - if ($this->read($url)) - $this->delete(); -} - - -/* - * Get content of url. Returns empty string if it was never successfully - * fetched. - */ -function get_content($url) -{ - $this->read($url); - return $this->data['content']; -} - - -/* - * Try to refetch all URLs in the database. - * Note: This is intented for background process use only as it may take - * a while to finish... - */ -function update_cache() -{ - $now = time(); - $pages = array(); - - $result = $this->table->safe_sql_select("WHERE nextupdate < $now", "url"); - - while (list($url) = $this->table->db->fetch_array($result)) - $pages[] = $url; - - $this->table->db->free($result); - - $this->_fetch_urls($pages, $now); -} - - -/* PRIVATE */ -function _update_cache($url, $content, $now) -{ - $contentmd5 = md5($content); - - if ($this->read($url)) - { - $interval = $this->data['updateinterval']; - $age = $now - $this->data['lastupdate']; - - if ($this->data['contentmd5'] == $contentmd5) - { - if ($age > ($interval * 2)) - $interval = $interval * 1.5; - - $tags = array("updateinterval" => $interval, "nextupdate" => $now + $interval); - } - else - { - if ($age < ($interval / 2)) - $interval = $interval / 1.5; - - if ($interval < $this->default_interval) - $interval = $this->default_interval; - - $tags = array("updateinterval" => $interval, "lastupdate" => $now, "nextupdate" => $now + $interval, "contentmd5" => $contentmd5, "content" => $content); - } - - $this->update($tags); - } - else - { - $tags = array("url" => $url, "updateinterval" => $this->default_interval, "lastupdate" => $now, "nextupdate" => $now + $this->default_interval, "contentmd5" => $contentmd5, "content" => $content); - $this->create($tags); - } -} - - -/* - * PRIVATE - * Fetch URL in array $urls and store update cache database accordingly - */ -function _fetch_urls($pages, $now) -{ - $pos = 0; - $fds = array(); - $urls = array(); - $content = array(); - $count = 0; - - for ($pos = 0; ($pos < count($pages)) && ($pos < $this->max_connections); $pos++) - { - debug("Opening $pages[$pos]", 10); - - if ($fd = fopen($pages[$pos], "r")) - { - socket_set_blocking($fd, false); - $fds[] = $fd; - $urls[] = $pages[$pos]; - $content[] = ""; - $count++; - debug("Opened $pages[$pos]", 10); - } - } - - while ($count > 0) - { - $read = 0; - - for ($i = 0; $i < count($fds); $i++) - { - if ($fds[$i]) - { - if (!feof($fds[$i])) - { - $data = fread($fds[$i], 4096); - $content[$i] .= $data; - $read += strlen($data); - debug("Read " . strlen($data) . " from $urls[$i]", 10); - } - - if (feof($fds[$i])) - { - fclose($fds[$i]); - $fds[$i] = 0; - $count--; - $this->_update_cache($urls[$i], $content[$i], $now); - debug("Finished $urls[$i]: " . strlen($content[$i]) . " bytes", 10); - - /* Schedule next url for retrieval */ - if ($pos < count($pages)) - { - if ($fd = fopen($pages[$pos], "r")) - { - socket_set_blocking($fd, false); - $fds[$i] = $fd; - $urls[$i] = $pages[$pos]; - $content[$i] = ""; - $count++; - debug("Opened $pages[$pos]", 10); - } - - $pos++; - } - } - } - } - - /* We are in non-blocking mode, be nice */ - if (($count > 0) && ($read == 0)) - { - sleep(1); - debug("Sleeping...", 10); - } - } -} - -} /* End class it_urlcache */ |