Welcome Guest, Not a member yet? Register   Sign In
how to dynamically change database ip depending on the user_agent type? (e.g. connect to a replica if googlebot)
#1

[eluser]Unknown[/eluser]
Hello,

I googled for this but couldn't find it.

What I want to achieve is the following.

Say I have 2 database servers. (say, A & A' - which is the replica of A) I want to direct to A' if the user_agents are bots (googlebot, bingbot etc)

Can I achieve this in codeigniter by changing the config/database.php file? or do I have to change config item values in model (e.g. in __construct) using config library?

I tried something like the following, but of course I can't use $this 'cos it's a config file.
Code:
if ($this->agent->is_robot())
{
            $db['live']['hostname'] = 'XXX.XXX.XXX.XXX'// database A';            
} else
{
            $db['live']['hostname'] = 'localhost'; // database A
}

I know this sounds silly, 'cos I'm trying to use a library in config file... (guess no library is loaded in this stage)

Any advice is appreciated & thanks in advance! Big Grin


Messages In This Thread
how to dynamically change database ip depending on the user_agent type? (e.g. connect to a replica if googlebot) - by El Forum - 09-07-2014, 04:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB