Grab code + a container with required extensions at
...but some pieces work on Windows as well
$pidsByTable = [];
foreach (array_keys(static::TABLE_TO_QUERY_MAPPING) as $table) {
$pid = pcntl_fork();
if ($pid === -1) { // fork failed
$this->logger->warning("Couldn't fork process for " . $table); continue;
} elseif ($pid) { // in parent
$pidsByTable[$table] = $pid; continue;
} // everything below this line in this loop is in the child process
\DB::purge(); // we need to create a new connection in the forked process
$queryClass = static::TABLE_TO_QUERY_MAPPING[$table];
$this->logger->debug('Starting to warm cache for ' . $table . ' in pid ' . $pid);
(new $queryClass(\DB::connection(), $this->logger))->warmCache();
$this->logger->debug('Warmed cache for ' . $table . ' in pid ' . $pid);
die(0); // immediately exit from child processes so we don't have additional forks
}
foreach ($pidsByTable as $table => $pid) { // if we're here, we're in the parent
pcntl_waitpid($pid, $status);
$this->logger->debug("Cache warm process for $table ($pid) done w\status $status");
}
#!/usr/bin/env php
<?php
if ($argc < 4) {
die("Usage: ./sleepAndWrite.php sleep_in_seconds filename output\n");
}
sleep($argv[1]);
error_log('Done sleeping. Writing contents to file.');
file_put_contents($argv[2], implode(' ', array_slice($argv, 3)));
Doesn't quite work right in php -S