- '/data/extranet/www/fluidbook/books/working/:/application/protected/fluidbookpublication/working/'
- '/data/extranet/www/fluidbook/books/links/:/application/protected/fluidbookpublication/links/'
- '/home/extranet/www/fluidbook/cache/unzip/:/application/storage/fluidbook/cache/unzip/'
+ - '/data/toolbox/protected/fluidbookpublication/cache/:/application/protected/fluidbookpublication/cache/'
- '/home/extranet:/home/extranet'
- '/data/extranet:/data/extranet'
- '/mnt:/mnt'
- '/mnt/sshfs/godzilla/data/fluidbook/docs/:/application/protected/fluidbookpublication/docs/'
- '/data/extranet/www/fluidbook/books/working/:/application/protected/fluidbookpublication/working/'
- '/data/extranet/www/fluidbook/books/links/:/application/protected/fluidbookpublication/links/'
- - '/data/extranet/www/fluidbook/cache/unzip/:/application/storage/fluidbook/cache/unzip/'
+ - '/home/extranet/www/fluidbook/cache/unzip/:/application/storage/fluidbook/cache/unzip/'
+ - '/data/toolbox/protected/fluidbookpublication/cache/:/application/protected/fluidbookpublication/cache/'
- '/home/extranet:/home/extranet'
- '/data/extranet:/data/extranet'
- '/mnt:/mnt'
class Farm
{
+
+ protected static $_forceServer = false;
protected static $_farmServers = [
['name' => 'alphaville', 'host' => 'fluidbook-processfarm', 'port' => 9000, 'weight' => 24, 'region' => 'UE'],
['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 2, 'region' => 'US'],
['name' => 'kingkong', 'host' => 'kingkong.cubedesigners.com', 'weight' => 6, 'region' => 'US'],
];
+ public static function forceServer($server)
+ {
+ self::$_forceServer = $server;
+ }
+
protected static function _pingCache()
{
return Files::mkdir(storage_path('fluidbookfarm')) . '/pings';
public static function pickOneServer()
{
+ if (self::$_forceServer) {
+ foreach (self::$_farmServers as $farmServer) {
+ if ($farmServer['name'] === self::$_forceServer) {
+ return $farmServer;
+ }
+ }
+ }
+
$hat = [];
$pingCache = self::_pingCache();
if (!file_exists($pingCache)) {
shuffle($hat);
$i = array_pop($hat);
return self::$_farmServers[$i];
+
}
public static function getFCGIConnexion(array $farm, $timeout = 240): NetworkSocket
}
public static function getFile($page, $format, $resolution, $withText, $withGraphics, $version, $resolutionRatio, $mobileFirstRatio, $path, $force = false)
+ {
+ $params = ['toolbox' => 1,
+ 'page' => $page,
+ 'format' => $format,
+ 'resolution' => $resolution,
+ 'withText' => $withText,
+ 'withGraphics' => $withGraphics,
+ 'version' => $version,
+ 'force' => $force,
+ 'out' => $path,
+ 'resolutionRatio' => $resolutionRatio,
+ 'mobileRatio' => $mobileFirstRatio];
+ return self::_getFile($params);
+ }
+
+
+ public static function getFileFromPDF($pdf, $page, $format, $resolution, $withText = true, $withGraphics = true, $version = 'html', $out = null, $force = false)
+ {
+ if (null === $out) {
+ $hash = Files::hashFileAttributes($pdf);
+ $out = Files::mkdir(protected_path('fluidbookpublication/cache/pdffiles/' . $hash));
+ }
+ $params = ['toolbox' => 1,
+ 'pdf' => $pdf,
+ 'page' => $page,
+ 'format' => $format,
+ 'resolution' => $resolution,
+ 'withText' => $withText,
+ 'withGraphics' => $withGraphics,
+ 'version' => $version,
+ 'force' => $force,
+ 'out' => $out];
+
+ return self::_getFile($params);
+ }
+
+ protected static function _getFile($params)
{
$start = microtime(true);
$farmer = self::pickOneServer();
- $params = ['toolbox' => 1, 'page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $path, 'resolutionRatio' => $resolutionRatio, 'mobileRatio' => $mobileFirstRatio];
-
$output = trim(self::sendRequest($farmer, 'process.php', $params));
if (file_exists($output)) {
}
$time = round(microtime(true) - $start, 4);
- $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t" . $time . "\t$page|$format|$resolution|$withText|$withGraphics|$version\t($res)\t>>" . $output . "\n";
+ $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t" . $time . "\t" . implode('|', $params) . "\t($res)\t>>" . $output . "\n";
error_log($log);
return $res;
}
+
public static function ping($echo = true, $force = false)
{
$cache = self::_pingCache();
use App\Fields\FluidbookComposition;
use App\Fields\FluidbookLocale;
use App\Fields\User;
+use App\Fluidbook\Farm;
use App\Fluidbook\Links;
use App\Http\Controllers\Admin\Operations\FluidbookPublication\CompositionOperation;
use App\Http\Controllers\Admin\Operations\FluidbookPublication\DeletefbOperation;
$resolution .= '-' . $q;
}
$compo = $this->composition[$page];
- $res = self::_getDocument($compo[0])->getFile($compo[1], $format, $resolution, $withText, $withGraphics, $version, $force);
- return $res;
+ return self::_getDocument($compo[0])->getFile($compo[1], $format, $resolution, $withText, $withGraphics, $version, $force);
+ }
+
+
+ public function getThumbFile($page, $format, $resolution = 'thumb', $withText = true, $withGraphics = true, $version = '', $force = false)
+ {
+ if ($this->pdfThumbnails) {
+ $thumbpdf = $this->getAssetDir() . $this->pdfThumbnails;
+ if (file_exists($thumbpdf)) {
+ return Farm::getFileFromPDF($thumbpdf, $page, $format, $resolution, $withText, $withGraphics, $version, null, $force);
+ }
+ }
+ return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version, $force);
+
}
public function addWidgets()