From: vincent@cubedesigners.com Date: Fri, 15 Apr 2022 09:45:25 +0000 (+0000) Subject: wip #5220 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0d8abe9dc57ad3cc65218633be1c1504e412e53c;p=cubeextranet.git wip #5220 @1 --- diff --git a/composer.json b/composer.json index b8ea51356..befc7f620 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "jaybizzle/crawler-detect": "^1.2", "ext-mbstring": "*", "ext-simplexml": "*", - "cubist/matomo": "dev-master" + "cubist/matomo": "dev-master", + "ext-curl": "*" } } diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index afbcc212a..3d386a0fd 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1558,6 +1558,9 @@ class wsMaintenance $daoBook = new wsDAOBook($core->con); $book = $daoBook->selectById($book_id, true); + + require_once ROOT . "/inc/ws/Util/html5/master/class.ws.html5.compiler.php"; + $resolutions = wsHTML5Compiler::getBookResolutions($book); $format = $book->parametres->imageFormat; @@ -1574,13 +1577,14 @@ class wsMaintenance if ($page == 'all') { $pages = range(1, $book->parametres->pages); } else { - $pages = [$page]; + $pages = cubeArray::parseRange($page); } shuffle($pages); foreach ($pages as $page) { foreach ($files as $file) { + echo ($force ? '!' : '') . $page . "-" . implode(',' . $file) . "\n"; $book->getFile($page, $file[0], $file[1], $file[2], $file[3], $file[4], $force); } } @@ -1593,18 +1597,40 @@ class wsMaintenance global $core; $book_id = $args[0]; + $force = isset($args[1]) && $args[1] != '0'; $dao = new wsDAOBook($core->con); $book = $dao->selectById($book_id); - $url = 'https://workshop.fluidbook.com/maintenance/processPage/' . $book_id . '/all/0'; - $ctx = stream_context_create(["http" => ["timeout" => 1]]); - $it = 2 * max(4, min(12, ceil(count($book->parametres->pages) / 20))); - for ($i = 0; $i < $it; $i++) { - file_get_contents($url, 0, $ctx); + $count = $book->parametres->pages; + $allPages = range(1, $count); + + $it = 2 * max(4, min(12, ceil($count / 20))); + + shuffle($allPages); + + $portions = array_chunk($allPages, ceil($count / $it)); + + foreach ($portions as $p) { + $url = 'https://workshop.fluidbook.com/maintenance/processPage/' . $book_id . '/' . implode(',', $p) . '/' . ($force ? '1' : '0'); + echo $url . "\n"; + self::timeoutRequest($url . '?PHPSESSID=' . session_id(), 1); } } + public static function timeoutRequest($url, $timeout) + { + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + + curl_exec($ch); + curl_close($ch); + } + public static function getAdditionalSettingsMap(): array { @@ -1861,14 +1887,15 @@ class wsMaintenance } foreach ($servers as $id => $farmer) { + echo '

' . $farmer['name'] . ' (' . $id . ')

'; if (isset($pings[$id]) && !$pings[$id]) { // If ping failed recently, we wait a bit before trying again. - if (rand(0, 9) === 5) { + if (rand(0, 9) != 5) { + echo '

Skipped, will try again soon

'; continue; } - break; } - echo '

' . $farmer['host'] . ' (' . $id . ')

'; + $cl = new CubeIT_CommandLine('/usr/local/fluidbook_processfarm/bin/ping'); $cl->setSSH($farmer['host'], 'fluidbookfarmer', '', $farmer['port'] ?? 22, '/home/extranet/.ssh/id_rsa'); $cl->execute(); diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index d04e2c5ba..cf69cdad8 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -127,10 +127,9 @@ class wsBook extends cubeMetier return $book->getAssetDir($sub); } - public static function precompileImages($book_id){ + public static function precompileImages($book_id) + { // Begin to generate files async - $url = 'https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id; - $ctx = stream_context_create(["http" => ["timeout" => 1]]); - file_get_contents($url, 0, $ctx); + wsMaintenance::timeoutRequest('https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id . '?PHPSESSID=' . session_id(), 1); } } \ No newline at end of file diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index de822dbf3..8c779b73b 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -56,13 +56,13 @@ class wsDocument extends cubeMetier const PNM_FILL = 2; protected static $_farmServers = [ - ['host' => 'elephantman.cubedesigners.com', 'port' => 22822, 'weight' => 1], - ['host' => 'fastandfurious.cubedesigners.com', 'port' => 22822, 'weight' => 1], - ['host' => 'paris.cubedesigners.com', 'port' => 22922, 'weight' => 2], - ['host' => 'paris.cubedesigners.com', 'port' => 22923, 'weight' => 1], - ['host' => 'godzilla.cubedesigners.com', 'weight' => 3], - ['host' => 'dracula.cubedesigners.com', 'weight' => 3], - ['host' => 'her.cubedesigners.com', 'weight' => 4], + ['name' => 'elephantman', 'host' => 'elephantman.cubedesigners.com', 'port' => 22822, 'weight' => 1], + ['name' => 'fastandfurious', 'host' => 'fastandfurious.cubedesigners.com', 'port' => 22822, 'weight' => 1], + ['name' => 'vmparis', 'host' => 'paris.cubedesigners.com', 'port' => 22922, 'weight' => 2], + ['name' => 'vincent', 'host' => 'paris.cubedesigners.com', 'port' => 22923, 'weight' => 1], + ['name' => 'godzilla', 'host' => 'godzilla.cubedesigners.com', 'weight' => 3], + ['name' => 'dracula', 'host' => 'dracula.cubedesigners.com', 'weight' => 3], + ['name' => 'her', 'host' => 'her.cubedesigners.com', 'weight' => 4], ]; protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5); @@ -476,6 +476,7 @@ class wsDocument extends cubeMetier public function _getFileFarm($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) { + $start = microtime(true); $farmer = self::pickOneFarmServer(); $params = ['page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $this->out, 'resolutionRatio' => $this->getResolutionRatio(), 'mobileRatio' => $this->getMobileFirstRatio()]; @@ -487,12 +488,21 @@ class wsDocument extends cubeMetier if (preg_match('|/data1/extranet/www/[^\s]+|', $o, $matches)) { $o = $matches[0]; } + if (file_exists($o)) { - return $o; + $res = $o; } else { echo $cl->output; + $res = false; } - return false; + $time = round(microtime(true) - $start, 4); + $log = '[' . $farmer['name'] . ']' . "\t\t\t\t" . $time . "\t\t\t\t$page|$format|$resolution|$withText|$withGraphics|$version\t\t\t\t$res\t\t\t\t$cl->output\n"; + + $fp = fopen(WS_DOCS . '/' . $this->document_id . '/farm.log', 'a+'); + fwrite($fp, $log); + fclose($fp); + + return $res; } public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)