1. Go to this page and download the library: Download ctw/ctw-temp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Ctw\Temp\Temp;
$temp = new Temp('www.example.com'); // base defaults to /var/tmp/php
define('APP_PATH_TEMP', $temp->createPath());
use Ctw\Temp\Temp;
// Full constructor signature (only $id is -cache', // optional extra directory
e.com/page-cache'
$temp->createPath(); // mkdir -p; throws RuntimeException if not writable
$temp->existsPath(); // bool
// Create and later delete a uniquely named file inside the directory:
$file = $temp->createFile('report', 'pdf'); // '/…/report-a1b2c3d4e5f6a7b8.pdf'
$temp->deleteFile($file);
$temp->clearPath(); // empty the directory, keep it (e.g. cache reset)
$temp->trashPath(); // same, in constant time; returns '/var/tmp/php/<hash>/.trash-9f3a1c2b7d4e5061'
$temp->deletePath(); // recursively remove the directory and its contents
$temp = new Temp('www.example.com', ['page-cache', 'v2']);
$temp->getPath(); // '/var/tmp/php/78b43994/www.example.com/page-cache/v2'
// bootstrap.php
define('APP_PATH_TEMP', new Temp(hostname_www())->createPath());
use Ctw\Temp\Temp;
use Ctw\Temp\TempTrait;
final class PageCache
{
use TempTrait;
public function invalidate(): void
{
$this->getTemp()->trashPath();
}
}
$cache = new PageCache()->setTemp(Temp::createFromPath(APP_PATH_TEMP));