Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2009, 07:07 PM
imported_silkroad imported_silkroad is offline
 
Join Date: Dec 2003
Posts: 563
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Set $vbphrase[] from Plugin ?

Hi!

I am thinking of some plugin code that does the following:
  1. Runs curl twice and pulls a URL from each site
  2. Compares to see which one is faster (by some significant margin)
  3. Changes the a value in $vbphrase[image_server] based on the results.
The reason I want to change $vbphrase[image_server] is that I use it in a number of templates in a URL, for example:

http://$vbphrase[image_server]/images/bigimage.jpg

I want to change the image_server based on the performance of the network.

More importantly, if one server is down, I want to automatically switch $vbphrase[image_server] over to the other one.

Any suggestions?
Reply With Quote
  #2  
Old 12-05-2009, 07:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It seems to me that if you are doing it in a plugin that will be run every page access, then maybe the easiest thing would be to just create a global variable to hold the answer and change the templates to use it instead of the phrase (or in addition to a phrase). I think you can just add to $vbulletin by making up a unique key, but to be honest I'm not sure if that's the "accepted" practice.
Reply With Quote
  #3  
Old 12-05-2009, 08:04 PM
imported_silkroad imported_silkroad is offline
 
Join Date: Dec 2003
Posts: 563
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
It seems to me that if you are doing it in a plugin that will be run every page access, then maybe the easiest thing would be to just create a global variable to hold the answer and change the templates to use it instead of the phrase (or in addition to a phrase). I think you can just add to $vbulletin by making up a unique key, but to be honest I'm not sure if that's the "accepted" practice.
That's what I thought... that someone would advise to use a Global Variable. I agree, but now I think I should not use a plugin (for performance reasons).

I think it is also better to simply run the script in a crontab file every 5 minutes, instead of with every page in a plugin.

In that case, a plug-in might not be the best way to go; better to simply write a script for cron and use a MySQL call to update $vbphrase[image_server] in the dB?

Code:
mysql_query("UPDATE phrase SET text='myfastserver.com' WHERE varname='image_server'") 
or die(mysql_error());
Reply With Quote
  #4  
Old 12-05-2009, 08:44 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ha - I hate being that predictable . But if you have an aversion to globals, it's likely that the plugin code and the eval of the template happen in the same php file so it could be local to that file. Making it global I guess just avoids having to worry about cases where something might be happening in a function call.

The cron idea sounds good to me, to be honest I don't know anything about updating the phrase in the database.
Reply With Quote
  #5  
Old 12-05-2009, 09:26 PM
imported_silkroad imported_silkroad is offline
 
Join Date: Dec 2003
Posts: 563
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Ha - The cron idea sounds good to me, to be honest I don't know anything about updating the phrase in the database.
I think that is what I will do...
  1. Run a cronfile that does the network check with curl
  2. Update $vbphrase[image_server] using MySQL and the phrase table.
Thanks for helping me brainstorm the approach.

One advantage of this approach is that I can easily change $vbphrase[] when working on a server (and can also easily disable cron when I need to). Also, when I add a third server to the mix, I can easily update the cron file and can avoid doing anything in vB.

--------------- Added [DATE]1260092915[/DATE] at [TIME]1260092915[/TIME] ---------------

Unfortunately, my idea did not work.

Followup post:

UPDATE phrase SET text='www.mybackup.com' WHERE varname='backup_server';
Reply With Quote
Reply


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:06 PM.


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.03564 seconds
  • Memory Usage 2,197KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete