Fastest way to load serialized data

Instead of load a serialized object every time and unserialize it, write it to the filesystem as php file and include() it.

Depending on the case, this might be premature optimization.

$s = serialize(['a' => 1, 'bla', 'b'=>['a'=> false]]);
$data = '<?php return ' . var_export(unserialize($s), true) . ';';
// check if data changed then write it
file_put_contents('temp_data.php', $data);
$out = include('temp_data.php');
var_dump($out);

A similar technique is used in template engines, where the {{ $content }} of template.blade.php gets rendered as <?= $content ?> in randomhash.php.

optimization #premature-optimization

Cache Warm Up

Two things in programming are complicated: Caching and yadda yadda... I know. When caching frontend pages on a low frequented site, someone has to wait for the page to be cached after it expired (assuming pages are cached with an expiry date).

For that, warming up the cache can be appropriate. Set up a cronjob that requests the sitemap.xml and sends a HEAD request to every page in there.

cache

Using a Custom Branch of a Library in Composer

To utilize your own branch of a library, incorporating fixes or modifications, follow these steps to update the composer file:

{
    "require": {
-       "kevinrob/guzzle-cache-middleware": "^3.3",
+       "kevinrob/guzzle-cache-middleware": "dev-feature-flysystem2",
        "league/flysystem": "^2.1"
    },
+   "repositories": [
+       {
+           "type": "vcs",
+           "url": "https://github.com/marcus-at-localhost/guzzle-cache-middleware"
+       }
+   ]
}

In this code snippet, "dev-feature-flysystem2" refers to a branch named feature-flysystem2 in the repository located at "https://github.com/marcus-at-localhost/guzzle-cache-middleware".

The "type": "vcs" entry indicates that the specified URL represents a Version Control System (VCS) repository, such as Git, Mercurial, or SVN. This configuration allows Composer to directly retrieve the package from the VCS repository when installing dependencies.