I dont know if my sessions are too big. Is there a way to see the size of a session. Thanks, Rahul
$size_of_session_estimate = strlen( serialize( $_SESSION ) );
Now, this is just an estimate, as the serialize handler is not used to serialize sessions, but it also won't be too far off.
That being said, unless you're storing a silly amount of data in the session, you probably don't need to worry about this.
This:
echo strlen(session_encode());
will give you the amount of disk space used by $_SESSION (assuming session.save_handler is the default value files), since session_encode() returns a string identical to the string stored in the session file.
It will also give a better indication of the amount of memory used, since session_encode() adds less metadata than serialize().
On a default Apache setup, you can see the session data as stored on disk with:
session_write_close();
echo file_get_contents(sys_get_temp_dir() . 'sess_' . session_id());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With