viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

Fix a bug in how timers work in webb site that was causing excessive processor usage, adjust the thumbs for some video sources, a=chris

Chris Pollett [2018-04-20 03:Apr:th]
Fix a bug in how timers work in webb site that was causing excessive processor usage, adjust the thumbs for some video sources, a=chris
Filename
src/configs/Createdb.php
src/data/default.db
src/library/FileCache.php
src/library/IndexManager.php
src/library/WebSite.php
diff --git a/src/configs/Createdb.php b/src/configs/Createdb.php
index 0b3063a70..099abc9da 100755
--- a/src/configs/Createdb.php
+++ b/src/configs/Createdb.php
@@ -483,15 +483,15 @@ $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634195',
     'http://i1.ytimg.com/vi/{}/default.jpg', '')");
 $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634196',
     'MetaCafe', 'video', 'http://www.metacafe.com/watch/{}',
-    'http://www.metacafe.com/thumb/{}.jpg', '')");
+    '/resources/blank.png?{}', '')");
 $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634197',
     'DailyMotion', 'video', 'http://www.dailymotion.com/video/{}',
-    'http://www.dailymotion.com/thumbnail/video/{}', '')");
+    '/resources/blank.png?{}', '')");
 $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634198',
     'Vimeo', 'video', 'http://player.vimeo.com/video/{}',
-    'http://www.yioop.com/resources/blank.png?{}', '')");
+    '/resources/blank.png?{}', '')");
 $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634199',
-    'Break.com', 'video', 'http://www.break.com/index/{}', '" .
+    'Break.com', 'video', '/resources/blank.png?{}', '" .
     NAME_SERVER . "/resources/blank.png?{}', '')");
 $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634200',
     'Yahoo News', 'rss', 'http://news.yahoo.com/rss/',
diff --git a/src/data/default.db b/src/data/default.db
index ccdf307d6..4aa3a401e 100644
Binary files a/src/data/default.db and b/src/data/default.db differ
diff --git a/src/library/FileCache.php b/src/library/FileCache.php
index a76428501..adeaccf78 100644
--- a/src/library/FileCache.php
+++ b/src/library/FileCache.php
@@ -137,8 +137,7 @@ class FileCache
         return false;
     }
     /**
-     * Stores in the cache a key-value pair
-     *
+     * Stores in the file cache a key-value pair
      *
      * @param string $key to associate with value
      * @param mixed $value to store
@@ -172,7 +171,8 @@ class FileCache
         return ($value % self::NUMBER_OF_BINS);
     }
     /**
-     *
+     * Deletes cache key value files and ram copies of key values stored in the
+     * this file cache
      */
     public function clear()
     {
@@ -186,7 +186,12 @@ class FileCache
         }
     }
     /**
+     * Used to mark a cache item, and keep track of rounds according to the
+     * marker algorith. This function determine if the cache is too full
+     * and if so eject an item.
      *
+     * @param string $key that was just read from or written to. Might need
+     *  to bbe marked according to marker algorithm
      */
     protected function updateCache($key)
     {
diff --git a/src/library/IndexManager.php b/src/library/IndexManager.php
index ee7d6b9a3..761987690 100644
--- a/src/library/IndexManager.php
+++ b/src/library/IndexManager.php
@@ -52,11 +52,12 @@ class IndexManager implements CrawlConstants
      */
     public static $indexes = [];
     /**
-     *
+     * List of entries of the form name of bundle => time when cached
+     * @var array
      */
     public static $index_times = [];
     /**
-     *
+     * Max number of IndexArchiveBundles that can be cached
      */
     const INDEX_CACHE_SIZE = 1000;
     /**
@@ -93,6 +94,9 @@ class IndexManager implements CrawlConstants
                 self::$indexes[$index_name]->setCurrentShard(0, true);
                 self::$index_times[$index_name] = time();
             }
+            /*
+               If too many cached discard oldest 1/3 of cached indices
+             */
             if (count(self::$indexes) > self::INDEX_CACHE_SIZE) {
                 $times = array_values(self::$index_times);
                 sort($times);
diff --git a/src/library/WebSite.php b/src/library/WebSite.php
index 80a8792ee..8a50f4178 100644
--- a/src/library/WebSite.php
+++ b/src/library/WebSite.php
@@ -795,12 +795,12 @@ class WebSite
                 $in_streams_with_data = $this->in_streams[self::CONNECTION];
             }
             $out_streams_with_data = $this->out_streams[self::CONNECTION];
-            if ($this->timer_alarms->isEmpty()) {
-                $timeout = null;
-                $micro_timeout = 0;
-            } else {
+             if ($this->timer_alarms->isEmpty()) {
+                 $timeout = null;
+                 $micro_timeout = 0;
+             } else {
                 $next_alarm = $this->timer_alarms->top();
-                $pre_timeout = max(0, microtime(true) - $next_alarm[0]);
+                $pre_timeout = max(0, $next_alarm[0] - microtime(true));
                 $timeout = floor($pre_timeout);
                 $micro_timeout = intval(($timeout - floor($pre_timeout))
                     * 1000000);
@@ -922,7 +922,14 @@ class WebSite
         return $out_data;
     }
     /**
+     * Used  by usual and internal requests to compute response  string of the
+     * web server to the web client's request. In the case of internal requests,
+     * it is sometimes usesful to return just the body of the response without
+     * HTTP headers
      *
+     * @param bool $include_headers whether to include HTTP headers at beginning
+     *      of reponse
+     * @return string HTTP response to web client request
      */
     protected function getResponseData($include_headers = true)
     {
@@ -1132,8 +1139,11 @@ class WebSite
         if ($connection) {
             if ($this->is_secure) {
                 stream_set_blocking($connection, 1);
-                stream_socket_enable_crypto($connection, true,
+                set_error_handler(null);
+                @stream_socket_enable_crypto($connection, true,
                     STREAM_CRYPTO_METHOD_TLS_SERVER);
+                set_error_handler(
+                    "seekquarry\\yioop\\configs\\yioop_error_handler");
                 stream_set_blocking($connection, 0);
             }
             $key = (int)$connection;
ViewGit