Commits

Michele Bini  committed 86c3d44

Make time synchronization check asynchronous.

  • Participants
  • Parent commits d77efe5

Comments (0)

Files changed (3)

File debian/changelog

+timekoin (1.9-deb36-dev1) unstable; urgency=low
+
+  * Made time synchronization check asynchronous.
+
+ -- Michele Bini <michele.bini@gmail.com>  Thu, 20 Sep 2012 22:50:22 +0200
+
 timekoin (1.9-deb36) unstable; urgency=low
 
   * Made activity icons more uniform.

File v1.9/main.php

 	// Do a random time sync check and report any errors to the user
 	if(rand(1,25) == 10)
 	{
-	        timekoin_debug_msg("main", "time sync check");
-		$poll_peer = filter_sql(file_get_contents("http://timekoin.net/time.php", FALSE, $context, NULL, 12));
-		$my_time = time();
-
-		if(abs($poll_peer - $my_time) > 15 && empty($poll_peer) == FALSE)
-		{
-			// Timekoin peer time is not in sync
-			mysql_query("UPDATE `options` SET `field_data` = '1' WHERE `options`.`field_name` = 'time_sync_error' LIMIT 1");
-		}
-		else
-		{
-			// Timekoin peer time is in sync
-			mysql_query("UPDATE `options` SET `field_data` = '0' WHERE `options`.`field_name` = 'time_sync_error' LIMIT 1");
-		}
+	  source_bg('timecheck.php');
 	}
 	//*****************************************************************************************************
 	//*****************************************************************************************************

File v1.9/timecheck.php

+<?PHP
+
+include 'configuration.php';
+include 'function.php';
+
+if (mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) &&
+    mysql_select_db(MYSQL_DATABASE) &&
+    mysql_table(mysql_query("SELECT GET_LOCK('timekoin_timecheck',0)")) == 1) {
+  $poll_peer = filter_sql(file_get_contents("http://timekoin.net/time.php", FALSE, $context, NULL, 12));
+  $my_time = time();
+  
+  if(abs($poll_peer - $my_time) > 15 && empty($poll_peer) == FALSE)
+    {
+      // Timekoin peer time is not in sync
+      mysql_query("UPDATE `options` SET `field_data` = '1' WHERE `options`.`field_name` = 'time_sync_error' LIMIT 1");
+    }
+  else
+    {
+      // Timekoin peer time is in sync
+      mysql_query("UPDATE `options` SET `field_data` = '0' WHERE `options`.`field_name` = 'time_sync_error' LIMIT 1");
+    }
+}
+
+?>