Hello guy's I newbie in cakephp 3.0. I know little bit cakephp 2.0. I configured my redis with cakephp 2.0 with this help of url But I don't know how to configure in cakephp 3.0 please help me
Since Cakephp 4 is out, I am currently studying it (which seems exists in Cakphp 3 as well) and seems like there is a way to do it. Not tested yet.
Following this: https://book.cakephp.org/4/en/development/sessions.html#cache-sessions
app.php
'Session' => [
'defaults' => 'cache', //Use the Cache class to save session
'handler' => [
'config' => 'session'
]
],
Following this link: https://book.cakephp.org/4/en/core-libraries/caching.html#redisengine-options
app.php
/*
* Configure the cache adapters.
*/
'Cache' => [
'session' => [
'className' => RedisEngine::class,
//`port` The port your Redis server is running on.
//`host` The host your Redis server is running on.
//`database` The database number to use for connection.
//`password` Redis server password.
//`persistent` Should a persistent connection be made to Redis.
//`timeout` Connection timeout for Redis.
//`unix_socket` Path to a unix socket for Redist.
],
],
I am going to test this out later on and make update if needed, but it really seems promising.
Update 2020-05-20: Tested, it work fine
You would set your session to use cache sessions inside the app.php file:
'Session' => [
'defaults' => 'cache'
]
Then, you would set your cache to redis:
'Cache' => [
'default' => [
'className' => 'Redis',
],
]
In vendor\cakephp\cakephp\src\Network\Session.php
you can see the default type of session.
They are listed as php, cake,cache , database.
$defaults = [
'php' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
]
],
'cake' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.serialize_handler' => 'php',
'session.use_cookies' => 1,
'session.save_path' => TMP . 'sessions',
'session.save_handler' => 'files'
]
],
'cache' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
],
'handler' => [
'engine' => 'CacheSession',
'config' => 'default'
]
],
'database' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
'session.serialize_handler' => 'php',
],
'handler' => [
'engine' => 'DatabaseSession'
]
]
]
Here is cache using default config of Cache. Maybe you want to use defualt as a File Cache.
In app.php
create a new cache config
'redis' => [
'className' => 'Redis',
'server'=>'127.0.0.1',
'port'=>6379
],
Then you can use your new cache config here.
'Session' => [
'cookie' => 'herewego',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
],
'handler' => [
'engine' => 'CacheSession',
'config' => 'redis'
]
],
Related
I have a straightforward application with php Laravel with the following channel configured for logs:
'stderr' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],
I've made sure the env variables LOG_CHANNEL and LOG_LEVEL are properly configured. Though docker doesn't output anything. Is there anyone that could give me more feedback on how to debug? Thanks so much
I'm using this and everything is working :
'stderr' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stdout',
'level' => 'debug',
],
],
Hope you found your solution !
In yii2 I need to use memcache plugin I've installed this also will be shown in phpinfo but I get the following error when running the project:
Invalid Configuration – yii\base\InvalidConfigException - MemCache requires PHP memcache extension to be loaded.
Cache configuration
'cache' => [
'class' => 'yii\caching\MemCache',
'servers' => [
[
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 60,
],
],
]
Maybe you have got memcached instead of memcache. Configuration in this case should be:
'cache' => [
'class' => 'yii\caching\MemCache',
'useMemcached' => true, // <--- here
'servers' => [
[
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 60,
],
],
],
I just uploaded my yii advanced project to my centos server, but I can't seem to get past the migrate phase. When I try to run yii migrate the following error occurred:
`Setting unknown property: yii\console\ErrorHandler::errorAction'
I have no idea why this happens, because it works fine when I run it locally on my windows computer.
My yii advance project is bit different than a normal Yii advanced. The backend has been separated from the frontend so it just contains the console and frontend directory.
common/config/main.php
$config = require(__DIR__ . '/main-console.php');
array_push($config['bootstrap'], 'site');
$config['components']['errorHandler'] = [
'errorAction' => 'site/error',
];
$config['components']['user'] = [
'identityClass' => 'frontend\models\User',
'enableAutoLogin' => true,
];
$config['components']['session'] = [
'name' => 'PHPFRONTSESSID',
'savePath' => sys_get_temp_dir(),
];
$config['components']['request'] = [
'cookieValidationKey' => 'IBzCJMjLWUaXMZemYUej',
'csrfParam' => '_frontendCSRF',
];
$config['components']['site'] = [
'class' => 'frontend\components\SiteComponent',
];
return $config;
main-console.php
$params = array_merge(
require(__DIR__ . '/params.php')
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log','debug'],
'sourceLanguage' => 'en-US',
'controllerNamespace' => 'frontend\controllers',
'aliases' => [
'#local_media' => '#frontend/web/uploads/media',
],
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#frontend/messages',
],
],
],
'assetManager' => [
'bundles' => false,
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning', 'trace'],
],
],
],
'defaultRoute' => 'site/view',
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => true,
'enableStrictParsing' => false,
'rules' => require('routes.php'),
],
],
'params' => $params,
];
Can someone give me some advies on how to solve this problem?
You problem is that you specify error action into common/config/main.php. Error action must be used only with web apps, not console. So move this to your frontend and backend configs separately:
$config['components']['errorHandler'] = [
'errorAction' => 'site/error',
];
There is no errorAction attribute in yii\console\ErrorHandler class. There is one in yii\web\ErrorHandler though. I'm not sure why this works on your local machine because it shouldn't. I guess some other configuration is in place there.
I want to use both memcached and apc at the same time for caching, how can I configure and use it in laravel.
By using the Cache facade you can specify what cache type you want to use.
Cache::store('memcached')->put('bar', 'baz', 10); // Using memcached
Cache::store('apc')->put('bar', 'baz', 10); // Using apc
As you can see in your app/config/cache.php there is already some preconfigured cache types set up:
'stores' => [
'apc' => [
'driver' => 'apc',
],
'array' => [
'driver' => 'array',
],
'database' => [
'driver' => 'database',
'table' => 'cache',
'connection' => null,
],
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache'),
],
'memcached' => [
'driver' => 'memcached',
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100,
],
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
],
You now need to make sure, memcached and APC are correctly installed on your system.
Using the Memcached cache requires the Memcached PECL package to be installed.
Using APC cache requires the APC package on your system
I have a site with a root domain and several sub domains, each a separate yii2 module. At the moment I have to log into each sub domain individually. I want to be able to log into the root directory and then be automatically logged into each of the sub domains. There are a few pages here and there on the web about achieving this but nothing that works.
at the moment I have the same setup in both main.php config files (i.e. the root domain and one of the sub domains that I am testing with)
'components' => [
'request' => [
'enableCookieValidation' => true,
'enableCsrfValidation' => true,
'cookieValidationKey' => 'XXXXXXX',
],
'user' => [
'class' => 'yii\web\User',
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_myapp',
'httpOnly' => true,
'path' => '/',
]
],
'session' => [
'name' => 'MYAPPSESSID',
'cookieParams' => [
'path' => '/',
],
],
When inspecting my cookies in Chrome after logging in with setup I see two cookies, one for the main site and one for the sub domain, they are both called MYAPPSESSID, and both containing different 'keys' that presumably hook up to the user info set on the PHP session. I get that these two cookies should be one cookie so that both domains hook up to the session user object - but I;ve tried all the different settings I can think of and can't get this to work.
To be able to log on all subdomains, use the following config:
'components' => [
'session' => [
// ...
'cookieParams' => [
'path' => '/',
'domain' => ".domain.com",
],
],
'user' => [
// ...
'identityCookie' => [
'name' => '_identity',
'path' => '/',
'domain' => ".domain.com",
],
],
'request' => [
// ...
'csrfCookie' => [
'name' => '_csrf',
'path' => '/',
'domain' => ".domain.com",
],
],
],
I figured this out in the end. The session->cookieParams needs a 'domain' set on both main.php config files, which is the top level domain name prefixed with a '.'. I did try this but the cookies were'n't being generated, and it turned out that it was because my local domains that I set in Mamp Pro were not formatted in a way that the cookies were expecting them. So my app was at http://myapp, and http://subdomain.myapp. It turns out that the cookie domain setting requires a top level domain (like .com). So I changed my hosts to http://myapp.local and http://subdomain.myapp.local. Then I set the cookie domains to .myapp.local and it worked.
here's my new config, which is on both the root domain and the sub domain. The user->identityCookie settings above turned out to be unnecessary btw.
'components' => [
'request' => [
'enableCookieValidation' => true,
'enableCsrfValidation' => true,
'cookieValidationKey' => 'XXXXXXX',
],
'user' => [
'class' => 'yii\web\User',
'identityClass' => 'common\models\User',
'enableAutoLogin' => true
],
'session' => [
'name' => 'MYAPPSESSID',
'cookieParams' => [
'path' => '/',
'domain' => '.myapp.local'
],
],