php - You cannot serialize or unserialize PDO instances CakePHP -
my cakephp giving problem , not know how solve it, tried update vendor error continues.
error.log
error: [pdoexception] cannot serialize or unserialize pdo instances request url: / stack trace: #0 [internal function]: pdo->__sleep() #1 vendor/cakephp/cakephp/src/cache/engine/fileengine.php(148): serialize(object(cake\orm\query)) #2 vendor/cakephp/cakephp/src/cache/cache.php(239): cake\cache\engine\fileengine->write('cake_views_post...', object(cake\orm\query)) #3 src/controller/postscontroller.php(494): cake\cache\cache::write('viewsposts', object(cake\orm\query)) #4 src/controller/postscontroller.php(57): app\controller\postscontroller->getpostssidebar() #5 vendor/cakephp/cakephp/src/controller/controller.php(262): app\controller\postscontroller->initialize() #6 [internal function]: cake\controller\controller->__construct(object(cake\network\request), object(cake\network\response), 'posts') #7 vendor/cakephp/cakephp/src/http/controllerfactory.php(79): reflectionclass->newinstance(object(cake\network\request), object(cake\network\response), 'posts') #8 vendor/cakephp/cakephp/src/http/actiondispatcher.php(93): cake\http\controllerfactory->create(object(cake\network\request), object(cake\network\response)) #9 vendor/cakephp/cakephp/src/http/baseapplication.php(83): cake\http\actiondispatcher->dispatch(object(cake\network\request), object(cake\network\response)) #10 vendor/cakephp/cakephp/src/http/runner.php(65): cake\http\baseapplication->__invoke(object(zend\diactoros\serverrequest), object(zend\diactoros\response), object(cake\http\runner)) #11 vendor/cakephp/cakephp/src/routing/middleware/routingmiddleware.php(62): cake\http\runner->__invoke(object(zend\diactoros\serverrequest), object(zend\diactoros\response)) #12 vendor/cakephp/cakephp/src/http/runner.php(65): cake\routing\middleware\routingmiddleware->__invoke(object(zend\diactoros\serverrequest), object(zend\diactoros\response), object(cake\http\runner)) #13 vendor/cakephp/cakephp/src/routing/middleware/assetmiddleware.php(88): cake\http\runner->__invoke(object(zend\diactoros\serverrequest), object(zend\diactoros\response)) #14 vendor/cakephp/cakephp/src/http/runner.php(65): cake\routing\middleware\assetmiddleware->__invoke(object(zend\diactoros\serverrequest), object(zend\diactoros\response), object(cake\http\runner)) #15 vendor/cakephp/cakephp/src/error/middleware/errorhandlermiddleware.php(81): cake\http\runner->__invoke(object(zend\diactoros\serverrequest), object(zend\diactoros\response)) #16 vendor/cakephp/cakephp/src/http/runner.php(65): cake\error\middleware\errorhandlermiddleware->__invoke(object(zend\diactoros\serverrequest), object(zend\diactoros\response), object(cake\http\runner)) #17 vendor/cakephp/cakephp/src/http/runner.php(51): cake\http\runner->__invoke(object(zend\diactoros\serverrequest), object(zend\diactoros\response)) #18 vendor/cakephp/cakephp/src/http/server.php(92): cake\http\runner->run(object(cake\http\middlewarequeue), object(zend\diactoros\serverrequest), object(zend\diactoros\response)) #19 webroot/index.php(37): cake\http\server->run() #20 {main}
composer show
$ composer show aura/installer-default 1.0.0 aura/intl 1.1.1 cakephp/bake 1.2.8 cakephp/cakephp 3.3.7 cakephp/chronos 1.0.0 cakephp/debug_kit 3.3.7 cakephp/migrations 1.6.3 cakephp/plugin-installer 0.0.15 dnoegel/php-xdg-base-dir 0.1 jakub-onderka/php-console-color 0.1 jakub-onderka/php-console-highlighter v0.3.2 jdorn/sql-formatter v1.2.17 mobiledetect/mobiledetectlib 2.8.22 user-agent strin... nikic/php-parser v2.1.1 psr/http-message 1.0.1 psr/log 1.0.0 psy/psysh v0.7.2 robmorgan/phinx v0.5.3 symfony/config v3.1.6 symfony/console v3.1.6 symfony/debug v3.1.6 symfony/filesystem v3.1.6 symfony/polyfill-mbstring v1.2.0 symfony/var-dumper v3.1.6 symfony/yaml v3.1.6 zendframework/zend-diactoros 1.3.7
edit
src/controller/postscontroller.php
if (($viewsposts = cache::read('viewsposts')) === false) { $viewsposts = tableregistry::get('viewsposts')->find('all') ->select([ 'count' => 'count(*)', 'posts.created', 'posts.id', ]) ->contain([ 'posts' ]) ->where([ 'posts.status' => 'published', 'posts.created >=' => new \datetime('-7 days') ]) ->group(['posts_id']) ->order(['count' => 'desc']) ->limit(5); cache::write('viewsposts', $viewsposts); /// line 494 }
fixed line
- cache::write('viewsposts', $viewsposts); + cache::write('viewsposts', $viewsposts->toarray());
your error caused file:
src/controller/postscontroller.php
@ line 494
you calling cake\cache\cache::write('viewsposts', object(cake\orm\query))
doesn't because can't serialize cake\orm\query (this called $results
or something, instead of doing want do.
$results->cache('viewposts');
cache result you. can more info cakephp website
caching loaded results - content included below well.
caching loaded results
when fetching entities don’t change may want cache results. query class makes simple:
$query->cache('recent_articles');
will enable caching on query’s result set. if 1 argument provided cache() ‘default’ cache configuration used. can control caching configuration used second parameter:
// string config name. $query->cache('recent_articles', 'dbresults'); // instance of cacheengine $query->cache('recent_articles', $memcache);
in addition supporting static keys, cache() method accepts function generate key. function give receive query argument. can read aspects of query dynamically generate cache key:
// generate key based on simple checksum // of query's clause $query->cache(function ($q) { return 'articles-' . md5(serialize($q->clause('where'))); });
the cache method makes simple add cached results custom finders or through event listeners.
when results cached query fetched following happens:
- the model.beforefind event triggered.
- if query has results set, returned.
- the cache key resolved , cache data read. if cache data not empty, results returned.
- if cache misses, query executed , new resultset created. resultset written cache , returned.
you cannot cache streaming query result.
Comments
Post a Comment