Caching Includes? »  Show posts from    to     

Icy Phoenix


English Chit Chat - Caching Includes?



mort [ Fri 21 Feb, 2020 21:42 ]
Post subject: Caching Includes?
Hey People,

When caching pages is it beneficial to include config files such as
Code: [Hide] [Select]
"includes/db-global.php / functions.php


Because it would save loading them when the template is cached? and still be available when caching is turned off ?



(I'm making a CMS)


Informpro [ Sun 23 Feb, 2020 15:29 ]
Post subject: Re: Caching Includes?
Hi mort,

if it's already PHP, there's nothing to cache.


mort [ Tue 25 Feb, 2020 14:02 ]
Post subject: Re: Caching Includes?
I don't have the luxury of a separate template system like IP uses - The html is included in the php files - If they were separate I would only cache the html files.


Informpro [ Wed 26 Feb, 2020 11:20 ]
Post subject: Re: Caching Includes?
If you're not writing PHP code that generates PHP, you don't need to cache it.
I don't think you need to cache much :).


mort [ Wed 26 Feb, 2020 12:22 ]
Post subject: Re: Caching Includes?
Unlike PHPBB tpl files which uses proxy VARS to swap in the php.

I'm separating all of the Db queries, and anything else that takes up most of the php files and swapping them back in with functions.

I started doing it with a "functions-config file I'm using to put them in - but it's getting pretty large, so no doubt I'll have to create a function file for every php file and call them back in using functions per file?

Too Easy! but time consuming. But it separates the html from the php, then I'll just cache the php file which will be a proxy html/tpl file.

Have a look at the html versus php in this example.


And this is only a "little one"!

Code: [Hide] [Select]
<?php

/**
* @package (c) 2008 - 2015 Gnu Arcade Script
* @version $Id: member_list.php Version.1.0
* @license http://www.fsf.org/ GNU lesser General Public Licence
*/

if (!defined('IN_ARCADE')) {die('Please use the front door');}

include "includes/db-global.php";
include "includes/config.php";

include "".TEMPLATE."overall_header.php";

$max = intval($limit_memberlist);

$page = isset($_GET['page']) ? intval($_GET['page']) : '';

if(empty($page)){$page = 1;

}

$limits = ($page - 1) * $max;

$sort_page = isset($_GET['sort']) ? htmlEsc($_GET['sort']) : '';

switch($sort_page) {
case 'id_asc':
$order = 'userid ASC';
break;
case 'id_desc':
$order = 'userid DESC';
break;
case 'name_asc':
$order = 'username ASC';
break;
case 'name_desc':
$order = 'username DESC';
break;
case 'plays_asc':
$order = 'plays ASC';
break;
case 'plays_desc':
$order = 'plays DESC';
break;
case 'rank_asc':
$order = 'user_level ASC';
break;
case 'rank_desc':
$order = 'user_level DESC';
break;
case 'status_asc':
$order = 'status ASC';
break;
case 'status_desc':
$order = 'status DESC';
break;
default:
$order = 'userid ASC';

}

/*** Start This is used only for the Count ***/

$pdo = "SELECT userid FROM " . USERS_TABLE . " WHERE activation_key=0 AND user_level!=0";
$stmt = $database->prepare($pdo);
$stmt->execute();

$row_count = $stmt->rowCount(PDO::PARAM_INT);

$totalcount = $row_count;
$totalpages = ceil($totalcount / $max);

/*** End This is used only for the Count ***/

$stmt = $database->prepare("SELECT

userid,
username,
user_level,
blog_level,
game_level,
status,
plays

FROM " . USERS_TABLE . " WHERE activation_key=0 AND user_level!=0 ORDER BY $order LIMIT $limits,$max");

$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo '
'.IMG_THL.''.$lang['memberlist'].''.IMG_THR.SCRST.'
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="sub-cat-a left boldp width10"> <a href="index.php?action=member_list&amp;sort=id_asc">'.ICO_SM_ASC.'</a> ID <a href="index.php?action=member_list&amp;sort=id_desc">'.ICO_SM_DESC.'</a></td>
<td class="sub-cat-a left boldp width20"> <a href="index.php?action=member_list&amp;sort=name_asc">'.ICO_SM_ASC.'</a> '.$lang['name'].' <a href="index.php?action=member_list&amp;sort=name_desc">'.ICO_SM_DESC.'</a></td>
<td class="sub-cat-a left boldp width20"> <a href="index.php?action=member_list&amp;sort=plays_asc">'.ICO_SM_ASC.'</a> '.$lang['plays'].' <a href="index.php?action=member_list&amp;sort=plays_desc">'.ICO_SM_DESC.'</a></td>
<td class="sub-cat-a left boldp width20"> <a href="index.php?action=member_list&amp;sort=rank_asc">'.ICO_SM_ASC.'</a> '.$lang['rank'].' <a href="index.php?action=member_list&amp;sort=rank_desc">'.ICO_SM_DESC.'</a></td>
<td class="sub-cat-a left boldp width5"> <a href="index.php?action=member_list&amp;sort=status_asc">'.ICO_SM_ASC.'</a> '.$lang['status'].' <a href="index.php?action=member_list&amp;sort=status_desc">'.ICO_SM_DESC.'</a></td>
<td class="sub-cat-a left boldp width10">'.$lang['profile'].'</td>
</tr>';

foreach( $result as $row )

{

$member_name = htmlEsc($row['username']);
$member_id = intval($row['userid']);
$user_level = intval($row['user_level']);
$blog_level = intval($row['blog_level']);
$game_level = intval($row['game_level']);
$plays = intval($row['plays']);


if($row['status'] >= time()-15*60){

$status=''.IMG_ONL.'';
}else{
$status=''.IMG_OFL.'';

}

include "".BLOCKS_COMMON."ranks.php";

echo '
<tr>
<td colspan="5" class="content-b left" width="100%">
</td>
</tr>
<tr>
<td class="content-b left boldp width10" style="padding: 3px;">'.$member_id.'</td>
<td class="content-b left boldp width20"><a href="'.U_PROFILE.$member_id.'">'.$member_name.'</a></td>
<td class="content-b left boldp width20">'.$plays.'<img style="float: right; padding-right: 5%;" src="'.RANKS_1.''.$AAA.'/></td>
<td class="content-b left boldp width10">';

if($user_level == '2'){echo '<span class="admin">'.$lang['admin'].'</span>';}else{
if($game_level == '2' || $blog_level == '2'){echo '<span class="jradmin">'.$lang['jr_admin'].'</span>';}else{
if($user_level != '2' || $game_level != '2' || $blog_level != '2'){echo '<span class="member">'.$lang['member'].'</span>';}

}
}

echo '
</td>
<td class="content-b left width5">'.$status.'</td>
<td class="content-b left width10">';

if($usrdata['user_level'] !=0){

echo '
&nbsp;<a href="'.U_PROFILE.$member_id.'">'.IMG_PRO2.'&nbsp;</a>';

}else{

echo '
&nbsp;<a href="javascript:void(0)"><img onclick=\'alert("'.$lang['view_profile_no'].'");\' src="'.ICON_PATH.'/icon-profile2.gif" alt="'.$lang['view_profile'].'" title="'.$lang['view_profile'].'" /></a>';

}

echo '
</td>
</tr>';

}

echo '
</table>'.SCRSB.IMG_THB.'
<p class="left boldp">'.$lang['pages'].':&nbsp;';

for($i = 1; $i <= $totalpages; $i++){

if($page == $i){$PageAt = 'page-at';}else{$PageAt = 'pagination';}

echo '
<a class="'.$PageAt.'" href="'.U_PAGES_MEMBER_LIST.''.$i.'">'.$i.'</a>';

}

echo '
</p>';

include "".TEMPLATE."overall_footer.php";

?>


Mighty Gorgon [ Fri 13 Mar, 2020 10:06 ]
Post subject: Re: Caching Includes?
Well Done avatar mort, it seems we have a new coder here.




Powered by Icy Phoenix