eWebTalk
Home Register New Posts FAQ eWebTalk TOS/Rules Advertise eTools

Go Back   eWebTalk Community > The Webmaster Forums > Programming & Scripting

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 16, 2007, 11:43 AM   #1
 
Nullified's Avatar


Nullified
Will you play with me?
eArcade Awards
Join Date: Dec 2004
Location: Outer Space
Posts: 2,086
Yapper(s): 1000547083807.10 (Donate)
 
Reply With Quote

K, I'm developing a simple script that allows me to edit/store my xhtml code in a database and have php pages extract it. However when caching each of the templates in php variables it doesn't seem to want to print them out. Can anyone please help:

index.php:
PHP Code:
 define('THIS_SCRIPT''index');

$templates = array(
    
'index'
);

require_once(
'include/global.php');

eval(
print_template('header'));
eval(
print_template(THIS_SCRIPT));
eval(
print_template('footer')); 

global.php:
PHP Code:
 require_once('config.php');
require_once(
'classes.php');
require_once(
'functions.php');

db_connect();

if (!
is_array($templates)) {
    
$templates = array();
}
$templates array_merge($templates, array(
    
'header',
    
'footer'
));
cache_templates($templates);
unset(
$templates); 

functions.php:
PHP Code:
 function db_connect() {
    global 
$config;
    if (isset(
$config['Server']['usepconnect'])) {
        
$link mysql_pconnect($config['Server']['host'], $config['Server']['username'], $config['Server']['password']);
    } else {
        
$link mysql_connect($config['Server']['host'], $config['Server']['username'], $config['Server']['password']);
    }
    if (!
$link) die('Unable to connect to ' $config['Server']['host'] . ': ' mysql_error());
        
$db_select mysql_select_db($config['Database']['name'], $link);
    if (!
$db_select) die ('Unable to connect to ' $config['Database']['name'] . ': ' mysql_error());
}

function 
cache_templates($templates) {
    global 
$db$config;
    
$templates mysql_query("SELECT title, code FROM template");
    while (
$template mysql_fetch_array($templates)) {
        
$templatecache["$template[title]"] = $template['code'];
    }
    @
mysql_free_result($templates);
    
//at this line of code all $templatecache variables are correct.
    //the function below is the next function called
}

function 
print_template($title$escape 0) {
    global 
$db$config$templatecache;
    
//$templatecache globalized
    //as of this line of code the $templatecache variable is empty.
    
if (!empty($templatecache["$title"])) {
        
$template['code'] = $templatecache["$title"];
    } else {
        
$template['code'] = $db->query_fetch("SELECT code FROM template WHERE title = '$title'");
    }



Why would the $templatecache variable be emptied/unset after that function ended?

Last edited by Nullified : Aug 16, 2007 at 11:48 AM.
Nullified is offline  
View profile Send PM to user Email user View user's homepage  
Word from our Sponsor:
Old Aug 16, 2007, 12:13 PM   #2
 
Nullified's Avatar


Nullified
Will you play with me?
eArcade Awards
Join Date: Dec 2004
Location: Outer Space
Posts: 2,086
Yapper(s): 1000547083807.10 (Donate)
 
Reply With Quote

Disregard last, I just had to globalize the variable in the cache_template function.

I do have another question though. Being that the xhtml code is being grabbed from the db and stored in php, if I update the db code, when will the site visitor have the updated code pulled form the db? Will they have to leave the site and come back (not using sessions).
Nullified is offline  
View profile Send PM to user Email user View user's homepage  
Old Aug 16, 2007, 1:03 PM   #3
 
A.Ah's Avatar


A.Ah
I run like a Monkey
eArcade Awards
Join Date: Aug 2004
Location: Ontario, Canada
Posts: 4,068
Yapper(s): 1273299994.40 (Donate)
Send a message via ICQ to A.Ah Send a message via AIM to A.Ah Send a message via MSN to A.Ah Send a message via Yahoo to A.Ah
 
Reply With Quote

From the way it looks coded, as long as the global variables are active, the templates will remain in cache. One way would be possiblt to check if an update has occured to the template? Possibly a global refresh time for your entire system, but considering most users remain on a website for few minutes, it would be kind of redundent...
__________________
»» eBypassnow Launched :: Bringing the e to free access
»» Click Here to Access! :: http://www.ebypassnow.com
»» Premium Access for eWeb Members!
A.Ah is offline  
View profile Send PM to user Email user View user's homepage  
Old Aug 16, 2007, 1:12 PM   #4
 
Nullified's Avatar


Nullified
Will you play with me?
eArcade Awards
Join Date: Dec 2004
Location: Outer Space
Posts: 2,086
Yapper(s): 1000547083807.10 (Donate)
 
Reply With Quote

what are you thoughts as far as speed? is it worth it to store html in the db and retrieve it with php as I am doing? Will the speed make up for the complicated editing? in your opinion. I really don't know if it'll be that beneficial since I don't see myself putting that much php related material on the pages.
Nullified is offline  
View profile Send PM to user Email user View user's homepage  
Old Aug 17, 2007, 12:17 PM   #5
 
A.Ah's Avatar


A.Ah
I run like a Monkey
eArcade Awards
Join Date: Aug 2004
Location: Ontario, Canada
Posts: 4,068
Yapper(s): 1273299994.40 (Donate)
Send a message via ICQ to A.Ah Send a message via AIM to A.Ah Send a message via MSN to A.Ah Send a message via Yahoo to A.Ah
 
Reply With Quote

I have recently been working on IR system based entirely on searching for images, and outputting them dynamically to increase security. I had the same questions as you did, are 'flat-file' templates better than ones stored in a database. Throughout most of my search, and finally in an application driven site, I think it is better to store them within a database or something more than simply a flat-file, especially if you will be expanding on the system after deployment. In terms of search/editing complexity, I was thinking of allowing the users to edit these templates much like how vB does, and the best way to accomplish this would be the use of database for storage and retrieval. In speed sense, its a harder question, many say that files are accessed faster than lets a database query since they are on the local system, while database can have a overhead, while others say that today's DB systems make this argument irrelevant. I would tend to agree with the latter arguement. Speed really boils down to be insignificant I think, especially if your database structure is optimized and well thoughtout.
__________________
»» eBypassnow Launched :: Bringing the e to free access
»» Click Here to Access! :: http://www.ebypassnow.com
»» Premium Access for eWeb Members!
A.Ah is offline  
View profile Send PM to user Email user View user's homepage  
Old Aug 29, 2007, 3:47 PM   #6
 
Nullified's Avatar


Nullified
Will you play with me?
eArcade Awards
Join Date: Dec 2004
Location: Outer Space
Posts: 2,086
Yapper(s): 1000547083807.10 (Donate)
 
Reply With Quote

Not even sure if I'm going to go through with it. It's going to be such a pain to edit the pages, and using an editor such as dreamweaver will be pretty much pointless.
Nullified is offline  
View profile Send PM to user Email user View user's homepage  
Old May 26, 2008, 7:50 AM   #7
uvwx669
Member
eArcade Awards
Join Date: May 2008
Posts: 95
Yapper(s): 1665.00 (Donate)
 
Reply With Quote

__________________
网站优化
uvwx669 is offline  
View profile Send PM to user  
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 8:52 PM.

Index  |  Members  |  Contact Us!  |  Referrals  |  Archive  |  Staff  | 
eWebTalk Community ©2004-2006 All Rights Reserved.   Hosted by: eVirtual Host - Host With the Best!
Powered by: vBulletin Version 3.0.7, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.