Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Beta Releases

Reply
 
Thread Tools
Cache the datastore in the filesystem Details »»
Cache the datastore in the filesystem
Version: 1.0, by Stadler Stadler is offline
Developer Last Online: Jul 2018 Show Printable Version Email this Page

Version: 3.0.3 Rating:
Released: 01-23-2005 Last Update: 03-20-2005 Installs: 10
Code Changes Additional Files  
No support by the author.

Ok, the purpose of this hack is to move the huge parts of the datastore,that are called each time you access a page, into a file unserialized and passed through var_export in order to save the time used to load the data from the database and to unserialize it. If you're using a PHP optimizer, like eAccelerator for example, this may save even more time I think. The result is, that huge arrays, like the forumcache are now loaded simply by executing
PHP Code:
require_once(DATASTORE_FILE_DIR.'datastore_cache.php'); 
in your init.php.

Additionally this saves 4 calls to the function unserialize, which is broken in PHP 5.0.3 and 4.3.10, so this should be a good work around until PHP 5.0.4 and/or PHP 4.3.11 has been released.

It tries to finish, what has been started in the code and AFAICS you can even find the beginnings of that in the init.php of vB3.0.6,although I'm still running vB 3.0.3, so I can't tell, that this works without problems in newer versions.

Some Notes:
  • I recommend to place rebuild_dscache.php into a protected directory and to alter the first chdir(...); in the script, so that no one can abuse this, by flooding your forum with calls to that script.
  • Additionally you should remove the backup-files named datastore_cache_TIMESTAMP.php in your includes dir (or wherever the datastore-cache is stored) from time to from to save disc-space.
  • Use this at your own risk and make sure to backup first before installing this hack.
  • This hack is not designed for a multi-webserver setup. So unless the data on the filesystem is being updated on the fly its not recommended to install this.
Changelog:
0.8.1 Alpha:
  • removed a relic of an old hack from dscache.txt
  • Added config_dscache.php
  • backups can be turned off now
  • you can change the directory, where the datastore_cache.php is stored now
  • Fixed a bug, that may cause unserialize-errors in the CP out of the blue
  • rebuild_dscache.php is verbosive now
0.8.2 Alpha:
  • Added CVS-Ids to some files
  • Added a note to rebuild_dscache.php
  • Added a note about PHP < 4.2.0 to dscache.txt
0.8.3 Alpha:
  • Removed some relics of the old backup functionality
  • some changes to make it possible to run it at the commandline (see below)
  • Allow to specify a key in the config-file, so this script will only run if you specify the correct key (-k KEY on the commandline or ?key=KEY in the URL)
  • You can make the script silent by adding -s respectively ?silent=1
1.0 (Final):
  • No changes at all. All files are the same as in Version 0.8.3 Alpha.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #22  
Old 01-25-2005, 05:33 PM
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Posts: 7,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I look forward to future versions.

Interesting that the vB developers had already coded this into vB by default. You just needed to activate it in config.php really.
Reply With Quote
  #23  
Old 01-25-2005, 06:14 PM
Stadler Stadler is offline
 
Join Date: Apr 2002
Location: Kiel, Germany
Posts: 142
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Erwin
I look forward to future versions.

Interesting that the vB developers had already coded this into vB by default. You just needed to activate it in config.php really.
Not really. They just started adding this, but it won't work without any changes.
Reply With Quote
  #24  
Old 01-25-2005, 07:45 PM
Stadler Stadler is offline
 
Join Date: Apr 2002
Location: Kiel, Germany
Posts: 142
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, I'm finished with the new version so far:

0.8.1 Alpha:
  • removed a relic of an old hack from dscache.txt
  • Added config_dscache.php
  • backups can be turned off now
  • you can change the directory, where the datastore_cache.php is stored now
  • Fixed a bug, that may cause unserialize-errors in the CP out of the blue
  • rebuild_dscache.php is verbosive now
Be aware, that this hack is still an Alpha and needs testing.
Reply With Quote
  #25  
Old 01-25-2005, 08:16 PM
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Posts: 7,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I installed 0.8.1 - works 100%. The backups were an annoyance and I'm glad you coded it so that they disappear. Thanks.
Reply With Quote
  #26  
Old 01-26-2005, 06:07 PM
kall's Avatar
kall kall is offline
 
Join Date: Apr 2004
Location: New Zealand
Posts: 2,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Parse error: parse error, unexpected T_STRING, expecting ')' in /home3/nzboards/public_html/forums/includes/datastore_cache.php on line 2833

Line 2833: 'description' => 'Kall\\'s private forum',
Reply With Quote
  #27  
Old 01-26-2005, 07:57 PM
Stadler Stadler is offline
 
Join Date: Apr 2002
Location: Kiel, Germany
Posts: 142
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In your functions.php (the hacked version) find the following:
PHP Code:
            $data_code preg_replace('/### (start|end) /''\' . "\\x23\\x23\\x23 \1 " . \''$data_code);
            
$datastore_cache file_get_contents(DATASTORE_FILE_DIR 'datastore_cache.php');

            
$datastore_cache preg_replace(
                
"/### start $title ###".
                
"(?:[^#]*(?:#(?!## end $title ###)[^#]*)*)".
                
"### end $title ###/",
                
"### start $title ###\n\$$varname = $data_code;\n### end $title ###",
                
$datastore_cache
            
); 
and replace it with the following:
PHP Code:
            $data_code str_replace(
                array(
                    
'### start ',
                    
'### end ',
                    
'{DATA_CODE}'
                
),
                array(
                    
'\' . "\\x23\\x23\\x23 start " . \'',
                    
'\' . "\\x23\\x23\\x23 end " . \'',
                    
'\' . "\\x7bDATA_CODE\\x7d" . \''
                
), $data_code);

            
$datastore_cache file_get_contents(DATASTORE_FILE_DIR 'datastore_cache.php');

            
$datastore_cache preg_replace(
                
"/### start $title ###".
                
"(?:[^#]*(?:#(?!## end $title ###)[^#]*)*)".
                
"### end $title ###/",
                
"### start $title ###\n\$$varname = {DATA_CODE};\n### end $title ###",
                
$datastore_cache
            
);
            
$datastore_cache str_replace('{DATA_CODE}'$data_code$datastore_cache); 
That should do the trick.
Reply With Quote
  #28  
Old 01-26-2005, 08:53 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm ... why don't you just write the variables without comments?
I think this could make it easier
Reply With Quote
  #29  
Old 01-26-2005, 09:46 PM
kall's Avatar
kall kall is offline
 
Join Date: Apr 2004
Location: New Zealand
Posts: 2,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Stadler
In your functions.php (the hacked version) find the following:
PHP Code:
            $data_code preg_replace('/### (start|end) /''\' . "\\x23\\x23\\x23 \1 " . \''$data_code);
            
$datastore_cache file_get_contents(DATASTORE_FILE_DIR 'datastore_cache.php');

            
$datastore_cache preg_replace(
                
"/### start $title ###".
                
"(?:[^#]*(?:#(?!## end $title ###)[^#]*)*)".
                
"### end $title ###/",
                
"### start $title ###\n\$$varname = $data_code;\n### end $title ###",
                
$datastore_cache
            
); 
and replace it with the following:
PHP Code:
            $data_code str_replace(
                array(
                    
'### start ',
                    
'### end ',
                    
'{DATA_CODE}'
                
),
                array(
                    
'\' . "\\x23\\x23\\x23 start " . \'',
                    
'\' . "\\x23\\x23\\x23 end " . \'',
                    
'\' . "\\x7bDATA_CODE\\x7d" . \''
                
), $data_code);

            
$datastore_cache file_get_contents(DATASTORE_FILE_DIR 'datastore_cache.php');

            
$datastore_cache preg_replace(
                
"/### start $title ###".
                
"(?:[^#]*(?:#(?!## end $title ###)[^#]*)*)".
                
"### end $title ###/",
                
"### start $title ###\n\$$varname = {DATA_CODE};\n### end $title ###",
                
$datastore_cache
            
);
            
$datastore_cache str_replace('{DATA_CODE}'$data_code$datastore_cache); 
That should do the trick.
I think I will wait until the serialise bug is fixed...I have destroyed my forums twice now trying to implement this...it also doesn't seem to play nicely with Ushop.

Good idea though, and thanks for the help.
Reply With Quote
  #30  
Old 01-27-2005, 08:40 PM
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Posts: 7,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This hack works but I've uninstalled it . It was really annoying to have to keep manually updating the datastore on each of my separate web servers. The crunch came when I put my forums offline to do a backup, but as I did not update the datastore manually, members could still access the forums, causing my 15 Gb database to become corrupted. Took me 28 hours to fix it manually as I didn't want to lose even 1 day of data. There is a slight page loading improvement, but I'd rather have the convenience.
Reply With Quote
  #31  
Old 01-27-2005, 08:54 PM
Stadler Stadler is offline
 
Join Date: Apr 2002
Location: Kiel, Germany
Posts: 142
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well yeah, if you're running this on a multi server setup, you need to synchronize everything on the fly and I suppose, that setting up such a system can be a lot of work, I guess.
Reply With Quote
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:27 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04402 seconds
  • Memory Usage 2,356KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (5)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete