Leave cache and logs out of synchronize with host machine and we have zero cost overhead when cache has been recalculated
PROJECT_NAME=my-project-name
# for linux
SYMFONY_CACHE_DIR=
SYMFONY_LOGS_DIR=
# for Mac OSX
SYMFONY_CACHE_DIR=/tmp/symfony
SYMFONY_LOGS_DIR=/tmp/symfony
services:
php:
container_name: ${PROJECT_NAME}_php
image: php:7.2-fpm
volumes:
- app_volume:/app:rw
environment:
SYMFONY_CACHE_DIR: ${SYMFONY_CACHE_DIR}
SYMFONY_LOGS_DIR: ${SYMFONY_LOGS_DIR}
class AppKernel extends Kernel
{
public function getCacheDir(): string
{
$cacheRootDir = (string) getenv('SYMFONY_CACHE_DIR');
if (empty($cacheRootDir)) {
return parent::getCacheDir();
}
return rtrim($cacheRootDir, '/') . '/cache/' . $this->environment;
}
public function getLogDir(): string
{
$logsRootDir = (string) getenv('SYMFONY_LOGS_DIR');
if (empty($logsRootDir)) {
return parent::getLogDir();
}
return rtrim($logsRootDir, '/') . '/logs';
}
}
class Kernel extends BaseKernel
{
use MicroKernelTrait;
public function getCacheDir(): string
{
$cacheRootDir = getenv('SYMFONY_CACHE_DIR') ?? $this->getProjectDir();
return rtrim($cacheRootDir, '/') . '/var/cache/' . $this->environment;
}
public function getLogDir(): string
{
$logsRootDir = getenv('SYMFONY_LOGS_DIR') ?? $this->getProjectDir();
return rtrim($logsRootDir, '/') . '/var/log';
}
}