function draw($points) { $xy = getXY($points); $map = getMap($xy['x'], $xy['y']); $set = getSet($points, $xy['x']); create($map, $set, $xy['x']); }
} $score = array(); foreach ($galaxytop as $key => $val) { $score[$key] = $val['score']; } array_multisort($score, SORT_DESC, $galaxytop); if (count($galaxytop) <= 10) { $max_count = count($galaxytop); } else { $max_count = 10; } mysql_query("TRUNCATE TABLE $table[universe_galaxy]"); for ($j = 0; $j < $max_count; $j++) { $galaxy_id = $galaxytop[$j]['id']; $total_members = $galaxytop[$j]['total_members']; $score = $galaxytop[$j]['score']; $asteroids = $galaxytop[$j]['asteroids']; $gal_xy = getXY($galaxy_id); $topic = getGalaxyTopic($galaxy_id); $sql_newgalaxytop = "INSERT INTO $table[universe_galaxy] (`galaxy_id`, `x`, `y`, `topic`, `total_members`, `score`, `asteroids`) VALUES ('$galaxy_id', '$gal_xy[x]', '$gal_xy[y]', '$topic', '$total_members', '$score', '$asteroids')"; mysql_query($sql_newgalaxytop) or die(mysql_error()); } /* Getting top 10 alliances. */ $alliancetop = array(array()); $sql_topalliance = "SELECT `id` FROM $table[alliance]"; $res_topalliance = mysql_query($sql_topalliance); $i = 0;
function resizeImage(&$filename, &$mime, $return = 0) { //start timing $time_start = getmicrotime(); /*** this disallows Win32 ***/ if (DIRECTORY_SEPARATOR != "/" && !EWIKI_IMAGERESIZE_WIN || strpos($mime, "image/") !== 0) { return false; } if (!isMemoryFriendly($filename)) { return false; } if (isCandyCane($filename)) { return false; } $rescaled_filename = $filename; $type = getTypeFromMIME($mime); $orig_image = getImageStream($rescaled_filename, $type); if (!isset($orig_image)) { return false; } getXY($orig_image, $orig_x, $orig_y); if (!isResizeNeeded($orig_x, $filename)) { return true; } getInitialResize($orig_image, $new_x, $new_y); $orig_image = doResize($orig_image, $new_x, $new_y, $type); $rescaled_filename = tempnam(EWIKI_TMP, "ewiki.img_resize_gd.tmp."); doSave($orig_image, $rescaled_filename, $type); if (isResizeNeeded($new_x, $rescaled_filename)) { ewiki_log("Resize beyond initial resize is needed. Carrying through.", 3); //set starting points for binary search $x_max = EWIKI_IMAGE_MAX_X - 1; $x_min = EWIKI_IMAGE_MIN_X; //set failsafe break to max number of iterations through the loop $failsafe = (int) (log($orig_x) + 1); while ($x_min <= $x_max && !isImageTolerable($rescaled_filename)) { ewiki_log("While loop initiated", 3); //somehow made it to an infinite loop, so get out if ($failsafe < 0) { return false; } //take a guess at the correct width $x_guess = (int) (($x_max + $x_min) / 2); if ($filename == $rescaled_filename) { $rescaled_filename = tempnam(EWIKI_TMP, "ewiki.img_resize_gd.tmp."); } #-- sizes $new_x = (int) $x_guess; $new_y = (int) ($x_guess * $orig_y / $orig_x); $new_image = doResize($orig_image, $new_x, $new_y, $type); doSave($new_image, $rescaled_filename, $type); #-- prepare next run imagedestroy($new_image); clearstatcache(); $failsafe--; $ftmp = filesize($rescaled_filename); ewiki_log("xguess: {$x_guess}, xmin: {$x_min}, xmax: {$x_max}, filesize: {$ftmp}", 3); if (filesize($rescaled_filename) < EWIKI_IMAGE_TOLERANCE) { $x_min = $x_guess + 1; } else { if (filesize($rescaled_filename) > EWIKI_IMAGE_MAXSIZE) { $x_max = $x_guess - 1; } } } ewiki_log("While loop ended", 3); } #-- stop imagedestroy($orig_image); clearstatcache(); #-- security check filesizes, abort if (!filesize($filename) || !filesize($rescaled_filename) || filesize($rescaled_filename) > EWIKI_IMAGE_MAXSIZE) { unlink($rescaled_filename); return $false; } #-- set $mime, as it may have changed (.gif) $mime = strtok($mime, "/") . "/" . $type; if (!strstr($filename, ".{$type}")) { unlink($filename); $filename .= ".{$type}"; } #-- move tmp file to old name copy($rescaled_filename, $filename); unlink($rescaled_filename); //end timing $time_end = getmicrotime(); $time = $time_end - $time_start; ewiki_log("{$time} seconds to perform resizing", 3); return true; }
$client = new Common\WebSocketClient($host, $prot); $data = $client->connect(); $id = substr($data, -7, 6); echo "{$i} : {$id}" . PHP_EOL; $result = $client->send(json_encode(getXY($id))); $fd = $client->getSocket()->sock; $clients[$fd] = [$id, $client]; echo "robot {$fd} create success" . PHP_EOL; usleep(20000); $client->send(json_encode(array('type' => 'robot'))); } echo "starttime: " . date("Y-m-d H:i:s") . PHP_EOL; $starttime = time(); while (1) { foreach ($clients as $index => $cli) { $result = $cli[1]->send(json_encode(getXY($cli[0]))); $send_count++; if ($result === false) { unset($clients[$index]); echo "{$cli[0]} error" . PHP_EOL; } else { $recvData = $cli[1]->recv(); /*if(!$recvData) { unset($clients[$index]); echo "{$index} recv error" . PHP_EOL; return; }*/ } } echo "send_count={$send_count}, etime: " . date("Y-m-d H:i:s") . PHP_EOL; if (empty($clients)) {