Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Liczenie Sesji
Lethys
post
Post #1





Grupa: Zarejestrowani
Postów: 642
Pomógł: 2
Dołączył: 9.03.2006

Ostrzeżenie: (30%)
XX---


Chce zrobic licznim online , i mysle ze moze mozna by bylo zrobic to liczac aktywne sejse (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

Moze zna ktos lepszy pomysl ...
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
elmoxxx
post
Post #2





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 27.10.2006

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


Chyba troche przesadziles z tym kodem.
Macie tytaj gotowa klase do zliczania osob online z modelowaniem i czterema stopniami obciazenia (m.in. tryb elite):

  1. <?php
  2. define(LOW_TRAFFIC, 0);
  3. define(MID_TRAFFIC, 1);
  4. define(HIGH_TRAFFIC, 2);
  5. define(ELITE_TRAFFIC, 3);
  6.  
  7. class OnlineMeter {
  8.  
  9. public static function getCount($traffic) {
  10.  
  11. $h = date("H");
  12.  
  13. $diff = $_SESSION['omgcts'];
  14.  
  15. if(($diff!=null && (time()-$diff)>300) || $diff == null) {
  16. if($traffic == LOW_TRAFFIC) 
  17. $peak = 5; else
  18. if($traffic == MID_TRAFFIC)
  19. $peak = 10; else
  20. if($traffic == HIGH_TRAFFIC) 
  21. $peak = 50; else
  22. if($traffic == ELITE_TRAFFIC) 
  23. $peak = 1000;
  24.  
  25. if($h < 1) $peak*=0.9; else
  26. if($h < 3) $peak*=0.4; else
  27.  if($h < 5) $peak*=0.01; else
  28.  if($h < 8) $peak*=0.2; else
  29.  if($h < 10) $peak*=1.1; else
  30.  if($h < 12) $peak*=1.5; else
  31.  if($h < 15) $peak*=2.1; else
  32.  if($h < 19) $peak*=3.1; else
  33. $peak*=4.1;
  34.  
  35. $_SESSION['omgcts'] = time();
  36.  
  37. $_SESSION['omgc'] = rand(1, $peak);
  38.  
  39.  
  40. }
  41. return $_SESSION['omgc'] ? $_SESSION['omgc'] : 0;
  42. }
  43. }
  44.  
  45.  
  46. echo 'People online: '.OnlineMeter::getCount(LOW_TRAFFIC);
  47.  
  48. ?>


Aha ilosc osob jest co 5 minut liczona.

Enjoy!
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: 3.10.2025 - 01:17