0

I have a server in one country, but most visits to my site come from another country (e.g., my server is in Germany but my site users are in the USA). This means that the ping time for my users is slow.

I’m going to buy a server in my users’ country, but I’m not going to move the data from my previous server (for various reasons). My site has to connect to the database to load the content.

Is it possible to make a connection from my new webserver to the database on my current server?

I imagine that it would be something like this.

$dbhost = "I think I should write the ip of the alternative server here";
$dbuser = ....;
$dbpass = ....;
$dbname = ....;
$dbconnection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

Is this correct?

TRiG
  • 1,181
  • 3
  • 13
  • 30
  • It depends on the setup and configuration of your server and your hoster. Generally this is possible, but it is also quite possible that your hoster won't allow it. – Gerald Schneider Jan 17 '17 at 10:23
  • It is also quite possible that you just move the bottleneck from the user->webserver connection to the webserver->database connection and you gain nothing at all. – Gerald Schneider Jan 17 '17 at 10:24
  • You can do this as long as you can setup VPN or whatever connection between two server. But as above @GeraldSchneider mentioned , it may not solve your user latency bottleneck. If you are using a N-Tier setup, you can setup a mock up server that doing above(than interrupt the existing services) and try it out. – mootmoot Jan 17 '17 at 10:29
  • @Gerald Schneider I'm gonna buy a VPS so I have some accessibility and as hosting I think I have full access.Are there any special configs for this purpose? – Alexander Jones Jan 17 '17 at 10:30
  • Take note that peer to peer connection between two server is NOT secure over internet, you need to setup VPN or some sort of secure connection handshake. – mootmoot Jan 17 '17 at 10:32
  • @mootmoot For user latency bottleneck I have another idea : if I can make this connection I can upload my data from previous server to the DB of new server. – Alexander Jones Jan 17 '17 at 10:33
  • Perhaps you should ask for tiny budget to test this out on a Cloud platform stay close to your user. (However, real deployment need VERY CAREFUL pricing research , there is a lot of traps and tricks on cloud pricing) – mootmoot Jan 17 '17 at 10:36

1 Answers1

2

Yes, you can do it but it is not a good idea for several reasons:

  1. You may suffer from high delay between your web server and database server. So, you may not get any performance gain after all.
  2. Your data will be exposed to public Internet unless you employ some VPN solution to encrypt your traffic.

If you want to try it, you need only to change the DB host of your connection. To verify the port is not closed and DB is accessible from your web server, you can try

$ telnet DB_server_ip 3306

where 3306 is the default port of MySQL server.

Khaled
  • 36,533
  • 8
  • 72
  • 99