Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Performance and going live

During development the shop is tuned for convenience: errors on screen, templates rebuilt on every change, the cache off. Customers need the opposite — speed and hidden details. Almost everything is switched on one back office page: "Advanced Parameters → Performance".

Performance settings

SettingIn developmentOn the production server
Debug modeOnOff
Template compilation"Recompile templates if the files have been updated""Never recompile template files"
Smarty cacheOffOn
Smart cache for CSSOffOn
Smart cache for JavaScriptOffOn
Data cacheOffMemcached or another one, if the server has it

"Smart cache" combines all style files into one and all scripts into one — that is exactly why a module registers files through registerStylesheet() instead of writing the tags itself.

Debug mode in the file

The switch in the back office changes a constant in the file config/defines.inc.php. On the production server it must look like this:

// config/defines.inc.php
define('_PS_MODE_DEV_', false);

With false errors are not shown to visitors, and Symfony runs in the prod environment with its cache in var/cache/prod.

Clearing the cache

After new code is deployed the cache is cleared:

php bin/console cache:clear --env=prod

The command removes the Symfony cache: the service container, routes, Twig templates. The "Clear cache" button on the "Performance" page does the same and also resets compiled Smarty templates and combined styles and scripts.

What you changedWhat to clear
services.yml, routes.yml, a Twig templatecache:clear
A Smarty template, CSS, JavaScriptThe "Clear cache" button
A class overrideThe file var/cache/prod/class_index.php

What slows a module down

CauseWhat to do
A database query in a hook on every pageCache the result, select only the columns you need
Styles and scripts on all pagesLoad them only where the module block is shown
A request to an external service while a page is shownMove it to a scheduled command
Creating an object in a loop: new Product($id)One DbQuery query for the whole list

Template cache in a hook

A block that rarely changes can be built once. Pass a cache id to fetch() and prepare the data only when there is no cache yet:

// modules/acmehello/acmehello.php
public function hookDisplayHome(array $params): string
{
    $template = 'module:acmehello/views/templates/hook/home.tpl';
    $cacheId = $this->getCacheId('acmehello_home');
 
    if (!$this->isCached($template, $cacheId)) {
        $this->context->smarty->assign([
            'greeting' => Configuration::get('ACMEHELLO_GREETING'),
        ]);
    }
 
    return $this->fetch($template, $cacheId);
}

With the Smarty cache on, the greeting block is built once and then served ready. When the setting is changed on the module page, the cache is reset with a $this->_clearCache($template) call after saving.

Before going live

What to checkWhy
The install folder is deletedOtherwise the shop can be reinstalled
The back office folder has a random nameBots try the /admin address
_PS_MODE_DEV_ is falseErrors and paths are hidden from visitors
HTTPS is on for all pages"Shop Parameters → General"
Friendly URLs are on"Shop Parameters → Traffic & SEO"
Email is sentA test email on the "E-mail" page
Test orders and customers are removedClean statistics
Write permissions only where neededvar, img, upload, download, translations
A scheduled backup of the database and filesRecovery after a failure
Maintenance mode is off"Shop Parameters → General → Maintenance"

Moving to a server

Files are copied to the server, the database is moved with a dump. After the move three things are fixed: the database parameters in app/config/parameters.php, the domain in the back office on the "Traffic & SEO" page in the "Set shop URL" block, and the cache is cleared.

Upgrading the shop

The core is upgraded with the upgrade module from PrestaShop — it is installed from the back office — after making a copy of the files and the database. The upgrade is first tested on a copy of the shop. Your modules and the child theme are not affected by an upgrade — unless you edited the core.

Common mistake

The code is deployed to the server, but the shop works the old way or fails with an unknown service error. In the prod environment the container and routes are not rebuilt by themselves. Clearing the cache is made part of the deployment order: copy the files — run cache:clear --env=prod — check the home page and the back office.

Thanks for reading!

Donate to the site — we work hard for you.