Forum

Geo balance code is broken

Paul 2016-03-20 18:35:56 UTC in WMSPanel functionality

I believe your Geo balance code has errors or is out of date.

https://github.com/WMSPanel/load-balancer/blob/master/geo-balancer/test.php

Around line 62,

These lines do not work and breaks script with syntax error, unexpected [ character
$balancer->setRegionServer(['JP','KR'], 'asia.example.com');

It took me about an hour of testing to find the error.
Bit I think this works:
$balancer->setRegionServer('JP','KR', 'asia.example.com');

So I guess, for sub regions you use square brackets [ ] ,
but for 2 digit country codes, there are no square brackets [ ] ?

Now I have fixed that and the runs, but it still does not work and do geo balance, the lines 100 (test links) always reverts to default server.

Paul 2016-03-20 18:39:54 UTC 

Can we have edit feature on forum?
"Now I have fixed that and the runs" lol. should say "Now I have fixed that and the script runs"

test.php lines 100 - 106 always echo the default server and do not get my country code from my IP.

Dmitry 2016-03-20 23:20:53 UTC 

Hello Paul,
this line is correct:
$balancer->setRegionServer(['JP','KR'], 'asia.example.com');
Reference code tested on PHP 5.5.30
Could you please check what return php -v?

Paul 2016-03-21 00:41:15 UTC 

Hi. its
PHP 5.3.3 (cli) (built: Jul 9 2015 17:39:00)

Alex Pokotilo 2016-03-21 00:50:17 UTC 

Please upgrade to 5.5 then

Paul 2016-03-21 15:40:39 UTC 

OK thanks guys. got it to work at last :)

Maybe put minimum version 5.5 on the Github guide?

For anyone else with centos:

yum update php didnt work
centos 6 only goes up to 5.3.
centos 7 goes to 5.4
so I followed this page https://www.mojowill.com/geek/howto-install-php-5-4-5-5-or-5-6-on-centos-6-and-centos-7/

My site is unavailable due to "DNS errors" after updating PHP. not sure what php has got to do with DNS! for now I access site via ip address. If anyone has any ideas what could be the problem with that?

Thanks

Paul 2016-03-21 15:45:40 UTC 

15 minutes later site works. Maybe cloudflare. I also clear cache on FF and site works.

Paul 2016-03-21 15:56:36 UTC 

For anyone else who might like this. Here is a list of country codes in CSV format.

I can sort data by region (eg, asia) copy/export the 2 digit codes & format somehow to add ' ', and paste in to geo balance script, saving a lot of time!

https://raw.githubusercontent.com/lukes/ISO-3166-Countries-with-Regional-Codes/master/all/all.csv

Yury Udovichenko 2016-03-22 02:30:17 UTC 

Hi Paul,

Thank you for the feedback and updates.

Post a reply


Post a new question

Categories:

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the Privacy Policy. If you want to know more or withdraw your consent to all or some of the cookies, please refer to the Privacy Policy.
By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to the use of cookies.