"jaybizzle/crawler-detect": "^1.2",\r
"ext-mbstring": "*",\r
"ext-simplexml": "*",\r
- "cubist/matomo": "dev-master"\r
+ "cubist/matomo": "dev-master",\r
+ "ext-curl": "*"\r
}\r
}\r
$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;
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);
}
}
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
{
}
foreach ($servers as $id => $farmer) {
+ echo '<h2>' . $farmer['name'] . ' (' . $id . ')</h2>';
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 '<p>Skipped, will try again soon</p>';
continue;
}
- break;
}
- echo '<h2>' . $farmer['host'] . ' (' . $id . ')</h2>';
+
$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();
return $book->getAssetDir($sub);\r
}\r
\r
- public static function precompileImages($book_id){\r
+ public static function precompileImages($book_id)\r
+ {\r
// Begin to generate files async\r
- $url = 'https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id;\r
- $ctx = stream_context_create(["http" => ["timeout" => 1]]);\r
- file_get_contents($url, 0, $ctx);\r
+ wsMaintenance::timeoutRequest('https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id . '?PHPSESSID=' . session_id(), 1);\r
}\r
}
\ No newline at end of file
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);
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()];
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)