Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Session handler - gc
tabbi
post
Post #1





Grupa: Zarejestrowani
Postów: 150
Pomógł: 3
Dołączył: 30.10.2010

Ostrzeżenie: (0%)
-----


Witam, czemu po czasie który wyznaczyłem nie usuwaja mi sie rekordy sesji z session handlera?
  1. public function gc($sess_maxlifetime) {
  2.  
  3. $old = (time() - $this->sess_duration);
  4.  
  5. $sql = "DELETE FROM `" . $this->table_name . "` WHERE `access` < " . intval($old) . ";";
  6. $qry = mysql_query($sql);
  7.  
  8. /**
  9.   * You can comment the optimize part, and optimize your tables in an independent way.
  10.   * In fact it's addvised that you do it, especially if you have a hight traffic load.
  11.   */
  12. if (mysql_affected_rows() > 0) { $this->optimize(); }
  13.  
  14. return true;
  15. }


Nawet gdy oznacze sess_duration na 2 sekundy to mi sie nie usuwa.? NIe za bardzo rozumiem czemu to nie działa ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Athlan
post
Post #2





Grupa: Developerzy
Postów: 823
Pomógł: 12
Dołączył: 18.12.2005

Ostrzeżenie: (0%)
-----


Kolego, przekleję Ci:
  1. <?php
  2. function open($save_path, $session_name)
  3. {
  4. global $sess_save_path;
  5.  
  6. $sess_save_path = $save_path;
  7. return(true);
  8. }
  9.  
  10. function close()
  11. {
  12. return(true);
  13. }
  14.  
  15. function read($id)
  16. {
  17. global $sess_save_path;
  18.  
  19. $sess_file = "$sess_save_path/sess_$id";
  20. return (string) @file_get_contents($sess_file);
  21. }
  22.  
  23. function write($id, $sess_data)
  24. {
  25. global $sess_save_path;
  26.  
  27. $sess_file = "$sess_save_path/sess_$id";
  28. if ($fp = @fopen($sess_file, "w")) {
  29. $return = fwrite($fp, $sess_data);
  30. fclose($fp);
  31. return $return;
  32. } else {
  33. return(false);
  34. }
  35.  
  36. }
  37.  
  38. function destroy($id)
  39. {
  40. global $sess_save_path;
  41.  
  42. $sess_file = "$sess_save_path/sess_$id";
  43. return(@unlink($sess_file));
  44. }
  45.  
  46. function gc($maxlifetime)
  47. {
  48. global $sess_save_path;
  49.  
  50. foreach (glob("$sess_save_path/sess_*") as $filename) {
  51. if (filemtime($filename) + $maxlifetime < time()) {
  52. @unlink($filename);
  53. }
  54. }
  55. return true;
  56. }
  57.  
  58. session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
  59.  
  60.  
  61. // proceed to use sessions normally
  62.  
  63. ?>


Funkcja gc() jest w session_set_save_handler jako ostatni argument. Pamiętaj, że jest to typ callback, czyli w Twoim przypadku będzie to nie string, a array($instancja_obiektu_sesji, "gc")
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.12.2025 - 07:29