I'm working on a module (a simple cms) with Kohana 3.2 and i'm getting this exception "Error reading session data."
I'm using native session and the funny thing is if i set a "default" group database connection the error isn't showed... (i'm using a custom connection group and i've set this database connection group to the user,role and user_token models).
here's my config file
auth.php
return array(
'driver' => 'orm',
'hash_method' => 'sha256',
'hash_key' => 'just a test 1',
'lifetime' => 1209600,
'session_type' => 'native',
'session_key' => 'just a test 2',
// Username/password combinations for the Auth File driver
'users' => array(
// 'luca' => 'e12afe0d3ead3d36191d86229d27057d96d9f2e063fe6f3e86699aaab5310d42'
// 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
),
);
session.php
return array(
'native' => array(
'name' => 'session_native',
'lifetime' => 43200,
),
'cookie' => array(
'name' => 'session_cookie',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'database' => array(
'name' => 'session_database',
'encrypted' => TRUE,
'lifetime' => 43200,
'group' => Pencil::db_group(),
'table' => 'sessions',
'columns' => array(
'session_id' => 'session_id',
'last_active' => 'last_active',
'contents' => 'contents'
),
'gc' => 500,
),
);
You set encrypted to true, so you need an encrypt key. In your config/encrypt.php add this:
<?php
return array(
'default' => array(
'key' => 'MY_RANDOM_KEY_I_MADE_UP_ALL_BY_MYSELF',
),
);
I would keep session_key set to 'auth_user' instead of your random key as well. I think key in that circumstance is not the same as a hash key.
Check your logs in application/logs to see if anything else is missing.
Related
i just started working with ZF2 ...
i want to initialize cache and session in config file and be able too use it in the application ( every where ) either using service manager or ... i have been searching Google for hours with no lock ... couldn't find anything useful in the documentations and ...
i tried this in module.config.php(Application module):
'service_manager' => array(
'factories' => array(
'cache' => '\Zend\Cache\StorageFactory',
),
),
'cache' => array(
'storage' => array(
'adapter' => 'Filesystem',
'options' => array(
'cache_dir' => __DIR__ . '/../../../data/cache'
),
),
'plugins' => array('WriteControl', 'IgnoreUserAbort'),
'options' => array(
'removeOnFailure' => true,
'exitOnAbort' => true,
'ttl' => 100
),
),
i got this error : While attempting to create cache(alias: cache) an invalid factory was registered for this instance type.
so whats the valid factory ?
so any one can help me out here ?
tanks...
Use a closure as factory instead because Zend\Cache\StorageFactory doesn't implement Zend\ServiceManager\FactoryInterface
'service_manager' => array(
'factories' => array(
'cache' => function () {
return Zend\Cache\StorageFactory::factory(array(
'storage' => array(
'adapter' => 'Filesystem',
'options' => array(
'cache_dir' => __DIR__ . '/../../../data/cache',
'ttl' => 100
),
),
'plugins' => array(
'IgnoreUserAbort' => array(
'exitOnAbort' => true
),
),
));
},
),
)
Btw. clean up your cache configuration and where you get the plugin in WriteControl and the option removeOnFailure from?
I've come to this topic from Google with the same error name but definitely different reason. Error could be caused by file not found error. If you get this error, check your config record
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
and be sure that needed file (mapper in my case) is located in the directory according to upper rules.
Could use some help. I have a drupal6 install that im having trouble with in terms of caching for authenticated users. Boost is handling the none authenticated caching very well. With my current setup, sessions cannot be created at all, when attempting to login the result is "You are not authorized to view this page". Memcache and apc are installed on the server and working according to phpinfo. Here is my current setup (without cacherouter):
include_once('./sites/all/modules/memcache/memcache.inc');
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['session_inc'] = './sites/all/modules/memcache/memcache-session.inc';
$conf['memcache_servers'] = array(
'127.0.0.1:11211' => 'default',
'127.0.0.1:11212' => 'block',
'127.0.0.1:11213' => 'content',
'127.0.0.1:11214' => 'filter',
'127.0.0.1:11215' => 'form',
'127.0.0.1:11216' => 'menu',
'127.0.0.1:11217' => 'page',
'127.0.0.1:11218' => 'update',
'127.0.0.1:11219' => 'views',
'127.0.0.1:11221' => 'session',
'127.0.0.1:11222' => 'users'
);
$conf['memcache_bins'] = array(
'cache' => 'default',
'cache_block' => 'block',
'cache_content' => 'content',
'cache_filter' => 'filter',
'cache_form' => 'form',
'cache_menu' => 'menu',
'cache_page' => 'page',
'cache_update' => 'update',
'cache_views' => 'views',
'session' => 'session',
'users' => 'users'
);
Before this setup, I was using cacherouter with authcache and had apc as the engine. Users could log in, but there was no actual caching happening for authenticated users. I have been reading everything I could find on this to get it going, doing various test and changing configurations, but without success. Here was the previous setup:
$conf['cacherouter'] = array(
'default' => array(
'engine' => 'apc',
'server' => array('127.0.0.1:11211'),
'shared' => TRUE,
'prefix' => '',
'path' => 'storage_bin/filecache',
'static' => FALSE
),
);
$conf['cache_inc'] = './sites/all/modules/authcache/authcache.inc';
$conf['memcache_servers'] = array(
'127.0.0.1:11211' => 'default',
'127.0.0.1:11212' => 'block',
'127.0.0.1:11213' => 'content',
'127.0.0.1:11214' => 'filter',
'127.0.0.1:11215' => 'form',
'127.0.0.1:11216' => 'menu',
'127.0.0.1:11217' => 'page',
'127.0.0.1:11218' => 'update',
'127.0.0.1:11219' => 'views'
);
$conf['memcache_bins'] = array(
'cache' => 'default',
'cache_block' => 'block',
'cache_content' => 'content',
'cache_filter' => 'filter',
'cache_form' => 'form',
'cache_menu' => 'menu',
'cache_page' => 'page',
'cache_update' => 'update',
'cache_views' => 'views'
);
The site is visible at www.thewildside.com. Any help on this would be greatly appreciated.
If anyone else runs into this, my solution was to ditch cacherouter (did not perform as expected), authcache(too beta), and boost (simply to avoid hitting apache at all for cached pages)… proceeding with Memcache API (the drupal module), memcache (the caching system), apc and varnish (3.0). Memcache API allows me to cache both to RAM via memcache and to the drupal db as backup in case memcache is not available (via memcache.db.inc). Benchmark to determine how much RAM to use for each cache component. I can also keep session info in memcache, but I have not noticed a great performance gain with this, so you may choose not to include memcache-session.inc. Create memcache instances for each drupal cache db (or use one default instance). Setup a cache bin for each instance you've created, and throw in reverse proxy settings and default ttl. Here is my whats in my setting.php file;
$conf = array(
'cache_inc' => './sites/all/modules/memcache/memcache.db.inc',
'memcache_key_prefix' => 'ws',
'session_inc' => './sites/all/modules/memcache/memcache-session.inc',
'memcache_servers' => array(
'unix:///var/run/memcached/memcached_wildside.sock' => 'default',
'unix:///var/run/memcached/memcached_wildside_apachesolr.sock' => 'apachesolr',
'unix:///var/run/memcached/memcached_wildside_block.sock' => 'block',
'unix:///var/run/memcached/memcached_wildside_content.sock' => 'content',
'unix:///var/run/memcached/memcached_wildside_filter.sock' => 'filter',
'unix:///var/run/memcached/memcached_wildside_form.sock' => 'form',
'unix:///var/run/memcached/memcached_wildside_media_youtube_status.sock' => 'media_youtube_status',
'unix:///var/run/memcached/memcached_wildside_menu.sock' => 'menu',
'unix:///var/run/memcached/memcached_wildside_objects.sock' => 'objects',
'unix:///var/run/memcached/memcached_wildside_page.sock' => 'page',
'unix:///var/run/memcached/memcached_wildside_path.sock' => 'path',
'unix:///var/run/memcached/memcached_wildside_rules.sock' => 'rules',
'unix:///var/run/memcached/memcached_wildside_update.sock' => 'update',
'unix:///var/run/memcached/memcached_wildside_views.sock' => 'views',
'unix:///var/run/memcached/memcached_wildside_views_data.sock' => 'views_data',
'unix:///var/run/memcached/memcached_wildside_session.sock' => 'session',
'unix:///var/run/memcached/memcached_wildside_users.sock' => 'users'),
'memcache_bins' => array(
'cache' => 'default',
'cache_apachesolr' => 'apachesolr',
'cache_block' => 'block',
'cache_content' => 'content',
'cache_filter' => 'filter',
'cache_form' => 'form',
'cache_media_youtube_status' => 'media_youtube_status',
'cache_menu' => 'menu',
'cache_objects' => 'objects',
'cache_page' => 'page',
'cache_path' => 'path',
'cache_rules' => 'rules',
'cache_update' => 'update',
'cache_views' => 'views',
'cache_views_data' => 'views_data',
'session' => 'session',
'users' => 'users'),
);
$conf['https'] = TRUE;
$conf['mimedetect_magic'] = '/usr/share/file/magic';
$conf['reverse_proxy'] = TRUE;
$conf['reverse_proxy_addresses'] = array('127.0.0.1');
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])){
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS']='on';
}else{
$_SERVER['HTTPS']='';
}
}
/* 1 day cache lifetime = 86400 */
$conf['cache_lifetime'] = 86400;
$conf['page_cache_maximum_age'] = 86400;
When setting up Varnish's config file (.vcl), just be sure that the syntax you use corresponds to the version of varnish you have installed.
I am creating a multi lingual application using ZF2.. and cannot determine how to add a part URL which will form the base of each URL regardless of modules.
http://localhost/en/us/application/index/index/
I totally understand how to configure /[:namespace[/:controller[/:action]]] using DI
http://localhost/application/index/index/
http://localhost/guestbook/index/index/
http://localhost/forum/index/index/
What I do not understand is how to configure a Part route which will be the base for all routes.. In ZF1 I used Route Chaining to achieve this..
So I need to configure a Part route of /[:lang[/:locale]] which applies site wide and then let the module configure /[:namespace[/:controller[/:action]]] or any other route necessary..
http://localhost/en/us/application/index/index/
http://localhost/zh/cn/application/index/index/
http://localhost/en/uk/forum/index/index/
I think what you are looking for is the child_routes configuration key. Take a look at how ZfcUser configures it's routing (here): it creates a base Literal route (/user) and then chains the sub-routes (/user/login, etc) onto it via the child_routes array.
I think something like this will do the trick for you:
'router' => array(
'routes' => array(
'myapp' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:lang[/:locale]]',
'defaults' => array(
'lang' => 'en',
'locale' => 'us',
),
),
'may_terminate' => false,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'index',
'action' => 'index',
),
),
),
),
),
),
Then in your controller you could do this to get the lang and locale:
$this->params()->fromRoute('lang');
$this->params()->fromRoute('locale');
I have a problem with my module views integration. I need to provide information about user who added video and timestamp. Video field is a CCK Embedded Media Field and it stores in content_field_3d_party_video table.
The schema is defined from the following code.
function MODULE_schema() {
$schema = array();
$schema['video_data'] = array(
'description' => t('Users and timestamps for video field'),
'fields' => array(
'value' => array(
'description' => t('Emfield value'),
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'description' => t('User id'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'timestamp' => array(
'description' => t('Timestamp'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('value'),
'indexes' => array(
'timestamp' => array('timestamp'),
'uid' => array('uid'),
),
);
return $schema;
}
The hook_views_data() implementation is the following.
function MODULE_views_data() {
$data = array();
$data['video_data']['table']['group'] = t('Video Data');
$data['video_data']['table']['join'] = array(
'node' => array(
'left_table' => 'content_field_3d_party_video',
'left_field' => 'field_3d_party_video_value',
'field' => 'value',
),
'users' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
$data['video_data']['value'] = array(
'title' => t('Video value'),
'relationship' => array(
'base' => 'content_field_3d_party_video',
'base field' => 'field_3d_party_video_value',
'field' => 'value',
'handler' => 'views_handler_relationship',
'label' => t('Video value'),
),
);
$data['video_data']['uid'] = array(
'title' => t('User id'),
'relationship' => array(
'base' => 'users',
'base field' => 'uid',
'field' => 'uid',
'handler' => 'views_handler_relationship',
'label' => t('User id'),
),
);
$data['video_data']['timestamp'] = array(
'title' => t('Timestamp field'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
return $data;
}
The table isn't included in the SQL query generated for the view.
SELECT node.nid AS nid,
node.title AS node_title,
node.language AS node_language,
node_data_field_3d_party_video.field_3d_party_video_embed AS node_data_field_3d_party_video_field_3d_party_video_embed,
node_data_field_3d_party_video.field_3d_party_video_value AS node_data_field_3d_party_video_field_3d_party_video_value,
...
node.type AS node_type,
node.vid AS node_vid
FROM node node
LEFT JOIN content_field_3d_party_video content_field_3d_party_video_video_data ON value = content_field_3d_party_video_video_data.field_3d_party_video_value
LEFT JOIN users users_video_data ON uid = users_video_data.uid
LEFT JOIN content_field_3d_party_video node_data_field_3d_party_video ON node.vid = node_data_field_3d_party_video.vid
WHERE ...
May you help me?
This is the solution the OP previously posted in the question.
To correctly join the table used for a CCK field, we must specify node_data_field_3d_party_video as left_table, instead of content_field_3d_party_video.
$data['video_data']['table']['join'] = array(
'node' => array(
'left_table' => 'node_data_field_3d_party_video',
'left_field' => 'field_3d_party_video_value',
'field' => 'value',
),
'users' => array(
'left table' => 'users',
'left_field' => 'uid',
'field' => 'uid',
),
);
I have the following action:
public function viewImageAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$filename = sanitize_filename($this->_request->getParam('file'), 'jpg');
$data = file_get_contents(APPLICATION_PATH . '/../private-files/fans-pictures/' . $filename);
$this->getResponse()
->setHeader('Content-type', 'image/jpeg')
->setBody($data);
}
And in my index.php before the application start I have:
/** Zend Cache to avoid unecessary application load **/
require_once 'Zend/Cache.php';
$frontendOptions = array(
'lifetime' => 3600,
'default_options' => array(
'cache' => $cache_flag,
'cache_with_cookie_variables' => true,
'make_id_with_cookie_variables' => false),
'regexps' => array(
'^(/.+)?/admin/?' => array('cache' => false),
'^(/.+)?/pictures/view-image/?' => array('cache' => true),
'^(/.+)?/authentication/?' => array('cache' => false),
'^(/.+)?/fan-profile/?' => array('cache' => false),
'^(/.+)?/fan-registration/?' => array('cache' => false))
);
$backendOptions = array(
'cache_dir' => APPLICATION_PATH . '/cache/pages/');
$cache = Zend_Cache::factory(
'Page', 'File', $frontendOptions, $backendOptions
);
$cache->start();
The cache works fine, except that if I try to access the url, like public/admin/pictures/view-image/file/63.jpg the headers come with text/html not image/jpeg.
Am I doing something wrong?
EDITED
I've tried:
'memorize_headers' => array('Content-type')
But nothing...
Also, I've notice that this type of caching (before the application start) can't be done on admin areas because the application need to run and check the session. So I need to put the chache as soon as possible to avoid the load of all components involved.
Any tips?
SOLUTION
The problem is with the location of the memorize_headers parameter.
I was trying this:
$frontendOptions = array(
'lifetime' => 3600,
'default_options' => array(
'cache' => $cache_flag,
'cache_with_cookie_variables' => true,
'memorize_headers' => array('Content-Type', 'Content-Encoding'),
'make_id_with_cookie_variables' => false),
'regexps' => array(
'^(/.+)?/admin/?' => array('cache' => false),
'^(/.+)?/admin/pictures/view-image/?' => array('cache' => true),
'^(/.+)?/authentication/?' => array('cache' => false),
'^(/.+)?/fan-profile/?' => array('cache' => false),
'^(/.+)?/fan-registration/?' => array('cache' => false))
);
The right location of this is out of the default_options key:
$frontendOptions = array(
'lifetime' => 3600,
'memorize_headers' => array('Content-Type', 'Content-Encoding'),
'default_options' => array(
'cache' => $cache_flag,
'cache_with_cookie_variables' => true,
//'cache_with_session_variables' => true,
'make_id_with_cookie_variables' => false),
'regexps' => array(
'^(/.+)?/admin/?' => array('cache' => false),
'^(/.+)?/admin/pictures/view-image/?' => array('cache' => true),
'^(/.+)?/authentication/?' => array('cache' => false),
'^(/.+)?/fan-profile/?' => array('cache' => false),
'^(/.+)?/fan-registration/?' => array('cache' => false))
);
Now it works.