Fixed #304 Calculate Server Time Offset [gh#304]

This commit is contained in:
Shoghi Cervantes 2013-05-29 18:20:48 +02:00
parent ddec63c4d4
commit 2f05a03e51
3 changed files with 28 additions and 13 deletions

View File

@ -26,7 +26,29 @@ the Free Software Foundation, either version 3 of the License, or
*/
set_time_limit(0);
date_default_timezone_set(@date_default_timezone_get());
date_default_timezone_set("GMT");
if(strpos(" ".strtoupper(php_uname("s")), " WIN") !== false){
$time = time();
$time -= $time % 60;
exec("time.exe /T", $hour);
$i = array_map("intval", explode(":", trim($hour[0])));
exec("date.exe /T", $date);
$j = array_map("intval", explode("/", trim($date[0])));
$offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
}else{
exec("date +%s", trim($t[0]));
$offset = round((intval($t) - time()) / 60) * 60;
}
$daylight = (int) date("I");
if($daylight === 0){
$offset -= 3600;
}
date_default_timezone_set(timezone_name_from_abbr("", $offset, $daylight));
gc_enable();
error_reporting(E_ALL ^ E_NOTICE);
ini_set("allow_url_fopen", 1);

View File

@ -73,16 +73,12 @@ function safe_var_dump($var, $cnt = 0){
function kill($pid){
switch(Utils::getOS()){
case "win":
ob_start();
passthru("%WINDIR%\\System32\\taskkill.exe /F /PID ".((int) $pid)." > NUL");
ob_end_clean();
exec("taskkill.exe /F /PID ".((int) $pid)." > NUL");
break;
case "mac":
case "linux":
default:
ob_start();
passthru("kill -9 ".((int) $pid)." > /dev/null 2>&1");
ob_end_clean();
exec("kill -9 ".((int) $pid)." > /dev/null 2>&1");
}
}

View File

@ -32,9 +32,6 @@ define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE
class Utils{
public static $online = true;
public static $ip = false;
public function run(){
}
public static function isOnline(){
return ((@fsockopen("google.com", 80) !== false or @fsockopen("www.linux.org", 80) !== false or @fsockopen("www.php.net", 80) !== false) ? true:false);
@ -73,11 +70,11 @@ class Utils{
public static function getOS(){
$uname = trim(strtoupper(php_uname("s")));
if(strpos($uname, "DARWIN") !== false or $uname === "DARWIN"){
if(strpos($uname, "DARWIN") !== false){
return "mac";
}elseif(strpos($uname, "WIN") !== false or $uname === "WIN"){
}elseif(strpos($uname, "WIN") !== false){
return "win";
}elseif(strpos($uname, "LINUX") !== false or $uname === "LINUX"){
}elseif(strpos($uname, "LINUX") !== false){
return "linux";
}else{
return "other";