Welcome Guest, Not a member yet? Register   Sign In
CI session database, lot of data
#1

[eluser]broadband[/eluser]
I have some temporary data which I decided to save in flashdata (for the next request).

There will be lot of data, more than 4 kB (which is maximum browser cookie size), so I decided to use
database.

Code:
$config['sess_cookie_name']     = 'session';
$config['sess_expiration']        = 7200;
$config['sess_expire_on_close']   = true;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = true;
$config['sess_table_name']      = 'ci_session';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']  = false;
$config['sess_time_to_update']   = 300;

This way the cookie on the client side, does not contain value, only session_id, expire, .... not user_data.

For testing purposes I tried to save a lot of session user_data in database. Second method test2() does not show anything. Has anybody experienced the same?

Code:
public function test()
  {
    $string = "test";
    for($i = 0; $i < 10;$i++) $string .= $string;

    $this->load->library('session');
    $this->session->set_userdata(array('test' => $string));
  }



Code:
public function test2()
  {
    $this->session->userdata('test');
  }

If I try with php native sessions:

Code:
public function test()
  {
    $string = "test";
    for($i = 0; $i < 10;$i++) $string .= $string;

    session_start();
    $_SESSION['test'] = $string;
  }


Code:
public function test2()
  {
    session_start();
    echo $_SESSION['test'];
  }

#2

[eluser]broadband[/eluser]
I checked in sql database, the user data is correct. I also "debugged" system/libraries/Session.php and I only found maybe the serialize/unserialize methods maybe causing the problem.

The php native sessions code works.
#3

[eluser]broadband[/eluser]
The problem only occurs when saving lots of data. String mb_strlen() = 80000. With $_SESSION it works.
#4

[eluser]InsiteFX[/eluser]
Read the bottom of this table!
Code:
-- ------------------------------------------------------------------------

--
-- Table structure for CodeIgniter ci_sessions.
--
DROP TABLE IF EXISTS `ci_sessions`;

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
  `session_id`    varchar(40)           DEFAULT '0' NOT NULL,
  `ip_address`    varchar(16)           DEFAULT '0' NOT NULL,
  `user_agent`    varchar(120)                      NOT NULL,
  `last_activity` int(10)      unsigned DEFAULT 0   NOT NULL,
  `user_data`     text,
  PRIMARY KEY (`session_id`),
  KEY `last_activity_idx` (`last_activity`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

-- ------------------------------------------------------------------------
--  `user_data` text,       COMMENT - maximum length of 65535 characters.
--  `user_data` mediumtext, COMMENT - maximum length of 16777215 characters.
--  `user_data` longtext,   COMMENT - maximum length of 4294967295 characters.
-- ------------------------------------------------------------------------
#5

[eluser]CroNiX[/eluser]
Also, you wrote different code for your 2 examples.

When you used $_SESSION, you ran session_start(); in each method before trying to set or read session data.

When you used CI session, you only loaded session in the test() method. You also need to load session in test2(), like you did for your $_SESSION. session_start() gets run when you load the session library. This is one of the libraries that should be autoloaded.
#6

[eluser]broadband[/eluser]
Thank you for the reply and the solution. The problem was user_data datatype. When I changed

Code:
ALTER TABLE `ci_session` CHANGE `user_data` `user_data` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL

everything worked fine.

And also yes I forgot to add $this->load->library('session'); in method test2()

Code:
public function test2()
  {
    $this->session->userdata('test');
  }

I just noticed when using database there is quite a performance hit.
#7

[eluser]broadband[/eluser]
Code:
public function test2()
  {
    $this->load->library('session')
    $this->session->userdata('test');
  }

Not able to edit previous post since:

Code:
Error Message

Due to a heavy increase of spam within our community, the privilege of being able to add links to content is currently reserved for active community members and those who have purchased our software.
#8

[eluser]InsiteFX[/eluser]
There's only two libraries that I autoload and those are the database and sessions because they are always used!




Theme © iAndrew 2016 - Forum software by © MyBB