[ADD-ON] improve forum speed

Mod that adds a birthday field to the users profile, theire age are displayed beside the posts, and on there birthday they will have a greeting popup
Forum rules
The content in this forum is dated Dec. 21 2005 and can be used as Archive only. This Forum is LOCKED and READ ONLY !

Postby Niels on Thu 16. Sep, 2004 00:08

this is the new section witch I now use on index....this can be used on all OS
Notice you will need a folder named /cache/index - and the www server need write access to this.

THIS POST WILL HAVE THE MOST UPDATED CODE, DO NOT USE CODE FOUND IN POST BELOW THIS POST, AS IT MIGHT BE A OLDER VERSION.

FInd the section of code added already to index.php - and replace by this

Code: Select all
// Birthday Mod, Show users with birthday
$cache_data_file = $phpbb_root_path."cache/index/birthday_". $board_config['board_timezone'] . ".dat";
if (@is_file($cache_data_file)  && empty($SID))
{
    $valid = (date('YzH',time(),0) - date('YzH',@filemtime($cache_data_file),0)<1) ? true : false;
} else
{
   $valid = false;
}

if ($valid )
{
   include ($cache_data_file);
   $birthday_today_list = stripslashes($birthday_today_list);
   $birthday_week_list = stripslashes($birthday_week_list);
} else
{
   $sql = ($board_config['birthday_check_day']) ? "SELECT user_id, username, user_birthday,user_level FROM " . USERS_TABLE. " WHERE user_birthday!=999999 ORDER BY username" :"";
   if($result = $db->sql_query($sql))
   {
      if (!empty($result))
      {
         $time_now = time();
         $this_year = create_date('Y', $time_now, $board_config['board_timezone']);
         $date_today = create_date('Ymd', $time_now, $board_config['board_timezone']);
         $date_forward = create_date('Ymd', $time_now+($board_config['birthday_check_day']*86400), $board_config['board_timezone']);
            while ($birthdayrow = $db->sql_fetchrow($result))
         {
               $user_birthday2 = $this_year.($user_birthday = realdate("md",$birthdayrow['user_birthday'] ));
               if ( $user_birthday2 < $date_today ) $user_birthday2 += 10000;
            if ( $user_birthday2 > $date_today  && $user_birthday2 <= $date_forward )
            {
               // user are having birthday within the next days
               $user_age = ( $this_year.$user_birthday < $date_today ) ? $this_year - realdate ('Y',$birthdayrow['user_birthday'])+1 : $this_year- realdate ('Y',$birthdayrow['user_birthday']);
               switch ($birthdayrow['user_level'])
               {
                  case ADMIN :
                        $birthdayrow['username'] = '<b>' . $birthdayrow['username'] . '</b>';
                        $style_color = 'style="color:#' . $theme['fontcolor3'] . '"';break;
                  case MOD :
                        $birthdayrow['username'] = '<b>' . $birthdayrow['username'] . '</b>';
                        $style_color = 'style="color:#' . $theme['fontcolor2'] . '"';break;
                  default: $style_color = '';
               }
               $birthday_week_list .= ' <a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $birthdayrow['user_id']) . '"' . $style_color .'>' . $birthdayrow['username'] . ' ('.$user_age.')</a>,';
            } else if ( $user_birthday2 == $date_today )
               {
               //user have birthday today
               $user_age = $this_year - realdate ( 'Y',$birthdayrow['user_birthday'] );
               switch ($birthdayrow['user_level'])
               {
                  case ADMIN :
                        $birthdayrow['username'] = '<b>' . $birthdayrow['username'] . '</b>';
                        $style_color = 'style="color:#' . $theme['fontcolor3'] . '"';break;
                  case MOD :
                        $birthdayrow['username'] = '<b>' . $birthdayrow['username'] . '</b>';
                        $style_color = 'style="color:#' . $theme['fontcolor2'] . '"';break;
                  default: $style_color = '';
               }
               $birthday_today_list .= ' <a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $birthdayrow['user_id']) . '"' . $style_color .'>' . $birthdayrow['username'] . ' ('.$user_age.')</a>,';
               }
         }
         if ($birthday_today_list) $birthday_today_list[ strlen( $birthday_today_list)-1] = ' ';
         if ($birthday_week_list) $birthday_week_list[ strlen( $birthday_week_list)-1] = ' ';
      }
      $db->sql_freeresult($result);
      if (empty($SID))
      {
         // stores the data set in a cache file
         $data = "<?php\n";
         $data .='$birthday_today_list = \'' . addslashes($birthday_today_list) . ".';\n";
         $data .='$birthday_week_list = \''.addslashes($birthday_week_list) . ".';\n?>";
         $fp = fopen( $cache_data_file, "w" );
         fwrite($fp, $data);
         fclose($fp);
      }
   }
}
Last edited by Niels on Wed 30. Mar, 2005 14:49, edited 7 times in total.
(if a how-to is EM ready, it will mostly be bullet prof, since a machine is more picky than a human. :D)
User avatar
Niels
Poster
Poster
 
Posts: 4390
Joined: Sat 27. Jul, 2002 15:46

Postby Blisk on Thu 16. Sep, 2004 09:25

Ok where to get this caching MOD?
I will try it.
And if you need some help with linux, I will share my experiences with you.
I have put in linux 100 of hours to setup redhat 9 now I am ojn fedora, which makes my pain in the a...... And still know wery little.
But I will manage like I did before.

About win, it is true, you can not leave machine withouth checking it regullary.
I suggest you have 2 machines one wn, and secon linux.
Blisk
Poster
Poster
 
Posts: 128
Joined: Wed 20. Aug, 2003 14:14

Postby Niels on Thu 16. Sep, 2004 21:19

the cacheing add-on, is the one posted abouve...
the mod describe how to add a large pice of code into index.php - simply add this section instead, and make shure you have created the cache folder with write access - after this replacement of the code, you index will respond faster (ofcouse only if the cache is less than 10 min old.)
(if a how-to is EM ready, it will mostly be bullet prof, since a machine is more picky than a human. :D)
User avatar
Niels
Poster
Poster
 
Posts: 4390
Joined: Sat 27. Jul, 2002 15:46

Postby Blisk on Fri 17. Sep, 2004 08:46

That look very nice, but where to put this code in which file and where to??
:?
Blisk
Poster
Poster
 
Posts: 128
Joined: Wed 20. Aug, 2003 14:14

Postby Afkamm on Tue 21. Sep, 2004 16:39

Blisk wrote:That look very nice, but where to put this code in which file and where to??
:?


index.php is the file the above code goes in. Use it to replace the current birthday mod code.

I was just wondering, would there be any speed increase if the data was saved/pulled to/from a MySQL table field? :roll:

The only downside would be that you'd need to create a new table in your database.
Marc :)
Remember, Google is your friend.
Afkamm
Poster
Poster
 
Posts: 36
Joined: Sat 04. Sep, 2004 02:26
Location: Scotland

Postby Blisk on Tue 21. Sep, 2004 17:05

this really increase the speed of forum.
TNX
Blisk
Poster
Poster
 
Posts: 128
Joined: Wed 20. Aug, 2003 14:14

Postby Niels on Mon 04. Oct, 2004 14:41

Replace this line of code, if will make the cache file be valid for max time ...

Code: Select all
[FIND]
$valid = (time()- @filemtime($cache_data_file)<600) ? true : false;

[REPLACE]
$valid = (date('YzH',time()) - date('YzH',@filemtime($cache_data_file))<1) ? true : false;
Last edited by Niels on Tue 05. Oct, 2004 08:25, edited 1 time in total.
(if a how-to is EM ready, it will mostly be bullet prof, since a machine is more picky than a human. :D)
User avatar
Niels
Poster
Poster
 
Posts: 4390
Joined: Sat 27. Jul, 2002 15:46

Postby Blisk on Mon 04. Oct, 2004 21:14

Niels wrote:Replace this line of code, if will make the cache file be valid for max time ...

Code: Select all
[FIND]
$valid = ......
[REPLACE]
$valid = ........


sorry what does this code??
Blisk
Poster
Poster
 
Posts: 128
Joined: Wed 20. Aug, 2003 14:14

PreviousNext

Return to Birthday [2.0.10/EM]

Who is online

Users browsing this forum: No registered users and 1 guest

cron