Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION SESSION exists and session_start() already called
#1
In an attempt to avoid repeatedly finding out Server/Client's IP/DNS and querying external sites for GeoIp info, I am trying to collect this info once and for all and pass it along to further pages via the SESSION variable using $_SESSION['myKey'].
I initiate the creation (or check for existence/home-brew timeout) of my session data quite early, namely from hook_theme-header.
The $_SESSION variable already exists and session_start() has already been called (I get a warning to that effect when I call session_start) (Why? If I understand correctly, Shawn claims GetSimple isn't relying on Session vars).

Unfortunately I have run into server memory overflows, and I am just asking myself whether it is acceptable to do a session_unset() . Will the internal operation of GetSimple be disrupted? I suspect not.

Any suggestions? Am I barking up against the wrong tree with my approach?
Reply
#2
Gs doesnt use sessions although some plugins do
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
What if you use the index-pretemplate hook?
Reply
#4
Did you check whats in the session? Maybe php auto sessions ?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
(2018-03-07, 02:31:17)shawn_a Wrote: Did you check whats in the session? Maybe php auto sessions ?
What I see in the $_SESSION variable is not much
Don't know about "cat", but "p01contact" comes from a plugin that's installed.
"fvVar" is my associative array, which I create.
{ "cat":null,
  "p01contact":{"pageloads":[1520354514,1520354516]},
  "fvVar":{ 
       "ipDns": { "server":{"ip":"8.7.6.5","dns":"do.main.be"},  "client":{"ip":"11.22.33.44","dns":"dom.ain.be"} }
       "geoIp": { ... }, 
       "expirationTime": 123...45
 }  }
At some point, I struggled with excessive memory usage: hundreds of MBs, overflowing the server limit and slowing down the pages, but with some cleaner programming, it remains stable at 5MB. Don't know why exactly it is better now. I didn't need to use session_start().
Reply
#6
A good practice is to check session status before you call session_start:

PHP5.4+
PHP Code:
if (session_status() == PHP_SESSION_NONE) {
  
session_start();

Reply
#7
What version of php? I remember having to do something similar because of a sesison bug
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#8
My isp uses Php 5.6.31, with session.auto_start off.
At hook_theme-header time, session_start() has already been called, headers_sent().
Occasionally, though, the /GS/ subsite grinds to a halt, including sometimes /GS/admin, while the production site at '/' still remains responsive as usual. I see no php memory increase while /GS is still working, but haven't been able to inspect that when these pages are blocked.
Restarting my browser sometimes helps. Waiting a few minutes too.
I've been reading around about (and half-understanding) the server-side file backup of $_SESSION being locked and header sizes getting out of hand. I suppose trying session_write_close() is a bit harsh w.r.t. plugin compatibility and may not address the problem anyway.
Thanks for your suggestions.
Reply




Users browsing this thread: 1 Guest(s)