vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Set $vbphrase[] from Plugin ? (https://vborg.vbsupport.ru/showthread.php?t=229577)

imported_silkroad 12-05-2009 07:07 PM

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?

kh99 12-05-2009 07:17 PM

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.

imported_silkroad 12-05-2009 08:04 PM

Quote:

Originally Posted by kh99 (Post 1925871)
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());


kh99 12-05-2009 08:44 PM

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.

imported_silkroad 12-05-2009 09:26 PM

Quote:

Originally Posted by kh99 (Post 1925923)
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';


All times are GMT. The time now is 01:21 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.01103 seconds
  • Memory Usage 1,725KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete