bnomei / kirby3-sqlite-cachedriver

Kirby 3 SQLite Cache-Driver
MIT License
2 stars 0 forks source link

SQLite3 object has not been correctly initialised or is already closed #1

Closed bnomei closed 3 years ago

bnomei commented 3 years ago

FORUM https://forum.getkirby.com/t/kirby3-boost-makes-loading-a-lot-of-pages-in-one-request-fast-unique-id/23580/7?u=bnomei

JonasHolfeld Hi again :slight_smile:

A few days later, i wanted to setup everything using the SQL-Lite server, but i get this Error:

Fatal error: Uncaught Error: The SQLite3 object has not been correctly initialised or is already closed in .../site/plugins/kirby3-sqlite- cachedriver/classes/SQLiteCache.php:175 Stack trace: #0 .../site/plugins/kirby3-sqlite-cachedriver/classes/SQLiteCache.php(175): SQLite3Stmt-

bindValue(':id', '...', 3) #1 ...//site/plugins/kirby3-sqlite-cachedriver/classes/SQLiteCache.php(107): Bnomei\SQLiteCache->remove(...')

2 .../site/plugins/kirby3-sqlite-cachedriver/classes/SQLiteCache.php(102): Bnomei\SQLiteCache->removeAndSet('index', Array, 0)

3 /.../site/plugins/kirby3-boost/classes/BoostIndex.php(54): Bnomei\SQLiteCache->set('index', Array, 0)

4 /.../site/plugins/kirby3-boost/classes/BoostIndex.php(37): Bnomei\BoostIndex->write() #5 [internal function]:

Bnomei\BoostIndex->__destruct() #6 {main} thrown in /.../site/plugins/kirby3-sqlite-cachedriver/classes/SQLiteCache.php on line 175 When running

site()->boost(); or

var_dump(site()->boostmark()); Do i need to initialize the SQLite Cachedriver plugin somehow?

Thank you!

bnomei commented 3 years ago

the sqlite file is optimized with pragmas. maybe your slite version does not support them.

please post your sqlite version: echo SQLite3::version();

and try these config values to disable all optimizations.

// other options
'bnomei.sqlite-cachedriver.pragmas-construct' => [],
'bnomei.sqlite-cachedriver.pragmas-destruct' => [],
jonasholfeld commented 3 years ago

Hi!

My SQLite version is 3.27.2

I tried disabling the optimizations and now get this error:

SQLite3Stmt::bindValue(): The SQLite3 object has not been correctly initialised

jonasholfeld commented 3 years ago

The error is thrown inside kirby3-sqlite-cachedriver/classes/SQLiteCache.php on line 175:

$this->deleteStatement->bindValue(':id', $key, SQLITE3_TEXT);

bnomei commented 3 years ago

i am running out of ideas. can you verify with some raw php sqlite commands that sqlite is working at all? like load an existing db? most examples found in google should do.

jonasholfeld commented 3 years ago

The SQLite3 extension for php is working fine.

So I tried a fresh Kirby3 installation on a different server with only the Boost + SQLite3CacheDriver plugins. The strange thing is: the Boost plugin seems to work fine with the SQLite Cachedriver, tested all the functions and it works. Though, every time I create a new page via the panel i get this Error:

The JSON response of the API could not be parsed

{"status":"error","exception":"Whoops\\Exception\\ErrorException","code":2,"message":"SQLite3Stmt::bindValue(): The SQLite3 object has not been correctly initialised","details":null,"file":"qlite\/site\/plugins\/kirby3-sqlite-cachedriver\/classes\/SQLiteCache.php","line":175}

But when I refresh, the page is there, with an ID in the boostid field and everything works fine.

bnomei commented 3 years ago

thanks for providing more information. i think i have an idea what is causing this.

will you try and remove detructor funciton from the class? and try again? https://github.com/bnomei/kirby3-sqlite-cachedriver/blob/1c1af952cd9aaa9597607a2b5fb136cb4408bba2/classes/SQLiteCache.php#L71

    public function __destruct()
    {
        if ($this->database) {
            $this->applyPragmas('pragmas-destruct');
            $this->database->close();
        }
    }
bnomei commented 3 years ago

if that fixes it then try again with the constructor but

 public function __destruct()
    {
        if ($this->database) {
            $this->applyPragmas('pragmas-destruct');
            // $this->database->close(); // 2nd try to just not close the db
        }
    }
jonasholfeld commented 3 years ago

Thanks, that fixed it. Pulled the new commits and tested everything, works like a charm.

Again: great plugin, thanks a lot!!