php-debugbar icon indicating copy to clipboard operation
php-debugbar copied to clipboard

[IDEA] No persistent storages

Open cesarreyes3 opened this issue 9 months ago • 3 comments

What if the storage is not persistent(by config) only temporary?, so once the records are displayed they are automatically deleted, ajax calls It would prevent the number of files from growing if you do not manually clear it, and files with debug information from being left by mistake.

https://github.com/php-debugbar/php-debugbar/blob/2be3ba62a75ead9e9d5f91f3a0779c95a696936f/src/DebugBar/Storage/FileStorage.php#L42-L45

// Example: $debugbar->setStorage(new FileStorage(__DIR__ . '/profiles', false)); //false for not persistent
class FileStorage implements StorageInterface
{
    protected $persist;

    public function __construct($dirname, $persist = true)
    {
        $this->dirname = rtrim($dirname, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        $this->persist = $persist;
    }

    public function get($id)
    {
        $fileName = $this->makeFilename($id);
        $data = json_decode(file_get_contents($fileName), true);
        if (! $this->persist) {
            unlink($fileName);
        }

        return $data;
    }

cesarreyes3 avatar Feb 14 '25 22:02 cesarreyes3

I explain the problem better, injecting the data into the header has the problem of maximum length allowed, and using the storage creates files with the data, the idea is to avoid injecting the data into the header, and use the openhandler to obtain the data by ajax, but at the same time prevent records from being saved in the storage, it would be like a temporary storage just to avoid maximum length allowed

Or maybe a storage that is temporary just for this

cesarreyes3 avatar Feb 14 '25 23:02 cesarreyes3

Hmm yeah with laravel-debugbar we 'garbage collect' the items; https://github.com/barryvdh/laravel-debugbar/blob/master/src/Storage/FilesystemStorage.php

Maybe something like this should be built-in indeed.

barryvdh avatar Feb 17 '25 12:02 barryvdh

If you have logrotate you could add a config, maxage is days to keep, and would be deleted daily

/var/www/your_app_path/storage/debugbar/*.json {
    daily
    rotate 0
    missingok
    nocreate
    maxage 1
    nomail
    nocompress
    ifempty
}

parallels999 avatar Feb 27 '25 15:02 parallels999