if (null === self::$_farmServers) {
self::$_farmServers = json_decode(file_get_contents('/home/toolbox/www/storage/fluidbookfarm/servers'), true);
}
+
return self::$_farmServers;
}
- public static function pickOneFarmServer()
+ public static function pickOneFarmServer($region = 'UE')
{
$hat = [];
$pings = json_decode(file_get_contents('/home/toolbox/www/storage/fluidbookfarm/pings'));
+ $allServers = [];
+ $regionServers = [];
+
foreach (self::getFarmServers() as $k => $farmServer) {
if (!isset($pings[$k]) || !$pings[$k]) {
continue;
}
- for ($i = 0; $i < $farmServer['weight']; $i++) {
+
+ $allServers[$k] = $farmServer['weight'];
+ if ($region == $farmServer['region']) {
+ $regionServers[$k] = $farmServer['weight'];
+ }
+ }
+
+ if (count($regionServers) == 0) {
+ $regionServers = $allServers;
+ }
+ foreach ($regionServers as $k => $weight) {
+ for ($i = 0; $i < $weight; $i++) {
$hat[] = $k;
}
}
+
shuffle($hat);
$i = array_pop($hat);
return self::$_farmServers[$i];
public function _getFileFarm($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)
{
$start = microtime(true);
- $farmer = self::pickOneFarmServer();
+ $farmer = self::pickOneFarmServer($this->region);
$params = ['page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $this->out, 'resolutionRatio' => $this->getResolutionRatio(), 'mobileRatio' => $this->getMobileFirstRatio()];
try {