Loadbalancing using PHP? Is this effective?
Server 1:
<?php
$servers = array("server2",
"server3",
"server4");
$server = $servers[array_rand($servers)];
header("Location: http://$server");
?>
Server 2:
Cloned Website
Server 3:
Cloned Website
Server 4:
Cloned Website
Server 5:
Database server, serving all servers
The DNS will be set to server 1 and then the script will redirect them to a random server in order to lower the load.
I could load up multiple server 1's using roundrobin DNS for example.
Furthermore I could improve the script on server 1 to check the health status every so often in order to make sure it doesn't redirect to a server that has gone down.
This could surely balance an unlimited amount of servers, I could just keep spinning up more loadbalancing servers via DNS if the load is super high? I don't see a problem with this, but clearly there must be as nobody uses this method
What I wanted to know is that would this be a good approach to loadbalancing, if not how exactly should it be done? Is there any problems with this approach?
php dns load-balancing reverse-proxy haproxy
add a comment |
Server 1:
<?php
$servers = array("server2",
"server3",
"server4");
$server = $servers[array_rand($servers)];
header("Location: http://$server");
?>
Server 2:
Cloned Website
Server 3:
Cloned Website
Server 4:
Cloned Website
Server 5:
Database server, serving all servers
The DNS will be set to server 1 and then the script will redirect them to a random server in order to lower the load.
I could load up multiple server 1's using roundrobin DNS for example.
Furthermore I could improve the script on server 1 to check the health status every so often in order to make sure it doesn't redirect to a server that has gone down.
This could surely balance an unlimited amount of servers, I could just keep spinning up more loadbalancing servers via DNS if the load is super high? I don't see a problem with this, but clearly there must be as nobody uses this method
What I wanted to know is that would this be a good approach to loadbalancing, if not how exactly should it be done? Is there any problems with this approach?
php dns load-balancing reverse-proxy haproxy
Why not use nginx as a load balancer?
– Harvey Fletcher
Nov 15 '18 at 9:35
I know, but I just want to know if there is hypothetically any issue with doing this instead of using NGINX, as this is a much simpler method to implement.
– Destroyer
Nov 15 '18 at 9:36
2
Using a scripting language as a load balancer is going to be a lot slower, and is probably one of the most serious reinventing-the-wheel cases I can think of. But if you're doing it as a learning experiment, then good luck - there's no fundamental reason it can't be done.
– iainn
Nov 15 '18 at 9:37
@iainn What would be the effect of this if I am already using it in a fairly large website that get's tens of thousands of hits an hour?
– Destroyer
Nov 15 '18 at 9:40
1
@Destroyer Well if you're using an actual HTTP redirect rather than proxying the requests then the obvious drawback is that you won't be able to use anything other than GET requests. If you're using this for anything more complicated than serving basic static content then that might be a show-stopper straight away. I really, really wouldn't recommend using anything like this in production, let alone for a large website. Apache, nginx, haproxy, even DNS round-robin are going to be far more reliable.
– iainn
Nov 15 '18 at 9:41
add a comment |
Server 1:
<?php
$servers = array("server2",
"server3",
"server4");
$server = $servers[array_rand($servers)];
header("Location: http://$server");
?>
Server 2:
Cloned Website
Server 3:
Cloned Website
Server 4:
Cloned Website
Server 5:
Database server, serving all servers
The DNS will be set to server 1 and then the script will redirect them to a random server in order to lower the load.
I could load up multiple server 1's using roundrobin DNS for example.
Furthermore I could improve the script on server 1 to check the health status every so often in order to make sure it doesn't redirect to a server that has gone down.
This could surely balance an unlimited amount of servers, I could just keep spinning up more loadbalancing servers via DNS if the load is super high? I don't see a problem with this, but clearly there must be as nobody uses this method
What I wanted to know is that would this be a good approach to loadbalancing, if not how exactly should it be done? Is there any problems with this approach?
php dns load-balancing reverse-proxy haproxy
Server 1:
<?php
$servers = array("server2",
"server3",
"server4");
$server = $servers[array_rand($servers)];
header("Location: http://$server");
?>
Server 2:
Cloned Website
Server 3:
Cloned Website
Server 4:
Cloned Website
Server 5:
Database server, serving all servers
The DNS will be set to server 1 and then the script will redirect them to a random server in order to lower the load.
I could load up multiple server 1's using roundrobin DNS for example.
Furthermore I could improve the script on server 1 to check the health status every so often in order to make sure it doesn't redirect to a server that has gone down.
This could surely balance an unlimited amount of servers, I could just keep spinning up more loadbalancing servers via DNS if the load is super high? I don't see a problem with this, but clearly there must be as nobody uses this method
What I wanted to know is that would this be a good approach to loadbalancing, if not how exactly should it be done? Is there any problems with this approach?
php dns load-balancing reverse-proxy haproxy
php dns load-balancing reverse-proxy haproxy
edited Nov 15 '18 at 9:36
Destroyer
asked Nov 15 '18 at 9:32
DestroyerDestroyer
42
42
Why not use nginx as a load balancer?
– Harvey Fletcher
Nov 15 '18 at 9:35
I know, but I just want to know if there is hypothetically any issue with doing this instead of using NGINX, as this is a much simpler method to implement.
– Destroyer
Nov 15 '18 at 9:36
2
Using a scripting language as a load balancer is going to be a lot slower, and is probably one of the most serious reinventing-the-wheel cases I can think of. But if you're doing it as a learning experiment, then good luck - there's no fundamental reason it can't be done.
– iainn
Nov 15 '18 at 9:37
@iainn What would be the effect of this if I am already using it in a fairly large website that get's tens of thousands of hits an hour?
– Destroyer
Nov 15 '18 at 9:40
1
@Destroyer Well if you're using an actual HTTP redirect rather than proxying the requests then the obvious drawback is that you won't be able to use anything other than GET requests. If you're using this for anything more complicated than serving basic static content then that might be a show-stopper straight away. I really, really wouldn't recommend using anything like this in production, let alone for a large website. Apache, nginx, haproxy, even DNS round-robin are going to be far more reliable.
– iainn
Nov 15 '18 at 9:41
add a comment |
Why not use nginx as a load balancer?
– Harvey Fletcher
Nov 15 '18 at 9:35
I know, but I just want to know if there is hypothetically any issue with doing this instead of using NGINX, as this is a much simpler method to implement.
– Destroyer
Nov 15 '18 at 9:36
2
Using a scripting language as a load balancer is going to be a lot slower, and is probably one of the most serious reinventing-the-wheel cases I can think of. But if you're doing it as a learning experiment, then good luck - there's no fundamental reason it can't be done.
– iainn
Nov 15 '18 at 9:37
@iainn What would be the effect of this if I am already using it in a fairly large website that get's tens of thousands of hits an hour?
– Destroyer
Nov 15 '18 at 9:40
1
@Destroyer Well if you're using an actual HTTP redirect rather than proxying the requests then the obvious drawback is that you won't be able to use anything other than GET requests. If you're using this for anything more complicated than serving basic static content then that might be a show-stopper straight away. I really, really wouldn't recommend using anything like this in production, let alone for a large website. Apache, nginx, haproxy, even DNS round-robin are going to be far more reliable.
– iainn
Nov 15 '18 at 9:41
Why not use nginx as a load balancer?
– Harvey Fletcher
Nov 15 '18 at 9:35
Why not use nginx as a load balancer?
– Harvey Fletcher
Nov 15 '18 at 9:35
I know, but I just want to know if there is hypothetically any issue with doing this instead of using NGINX, as this is a much simpler method to implement.
– Destroyer
Nov 15 '18 at 9:36
I know, but I just want to know if there is hypothetically any issue with doing this instead of using NGINX, as this is a much simpler method to implement.
– Destroyer
Nov 15 '18 at 9:36
2
2
Using a scripting language as a load balancer is going to be a lot slower, and is probably one of the most serious reinventing-the-wheel cases I can think of. But if you're doing it as a learning experiment, then good luck - there's no fundamental reason it can't be done.
– iainn
Nov 15 '18 at 9:37
Using a scripting language as a load balancer is going to be a lot slower, and is probably one of the most serious reinventing-the-wheel cases I can think of. But if you're doing it as a learning experiment, then good luck - there's no fundamental reason it can't be done.
– iainn
Nov 15 '18 at 9:37
@iainn What would be the effect of this if I am already using it in a fairly large website that get's tens of thousands of hits an hour?
– Destroyer
Nov 15 '18 at 9:40
@iainn What would be the effect of this if I am already using it in a fairly large website that get's tens of thousands of hits an hour?
– Destroyer
Nov 15 '18 at 9:40
1
1
@Destroyer Well if you're using an actual HTTP redirect rather than proxying the requests then the obvious drawback is that you won't be able to use anything other than GET requests. If you're using this for anything more complicated than serving basic static content then that might be a show-stopper straight away. I really, really wouldn't recommend using anything like this in production, let alone for a large website. Apache, nginx, haproxy, even DNS round-robin are going to be far more reliable.
– iainn
Nov 15 '18 at 9:41
@Destroyer Well if you're using an actual HTTP redirect rather than proxying the requests then the obvious drawback is that you won't be able to use anything other than GET requests. If you're using this for anything more complicated than serving basic static content then that might be a show-stopper straight away. I really, really wouldn't recommend using anything like this in production, let alone for a large website. Apache, nginx, haproxy, even DNS round-robin are going to be far more reliable.
– iainn
Nov 15 '18 at 9:41
add a comment |
1 Answer
1
active
oldest
votes
At the first place most of the server load rely on Sql and heavy query,
So instead of making multiple servers to handle request. You can do this
- Make Sql replica (Slave server) use it for reading and user master for writing.
- Use Memcache or Redis to prevent getting common data from database all the time.
- Prevent Unnecessary load/query.
- Use CDN
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53316289%2floadbalancing-using-php-is-this-effective%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
At the first place most of the server load rely on Sql and heavy query,
So instead of making multiple servers to handle request. You can do this
- Make Sql replica (Slave server) use it for reading and user master for writing.
- Use Memcache or Redis to prevent getting common data from database all the time.
- Prevent Unnecessary load/query.
- Use CDN
add a comment |
At the first place most of the server load rely on Sql and heavy query,
So instead of making multiple servers to handle request. You can do this
- Make Sql replica (Slave server) use it for reading and user master for writing.
- Use Memcache or Redis to prevent getting common data from database all the time.
- Prevent Unnecessary load/query.
- Use CDN
add a comment |
At the first place most of the server load rely on Sql and heavy query,
So instead of making multiple servers to handle request. You can do this
- Make Sql replica (Slave server) use it for reading and user master for writing.
- Use Memcache or Redis to prevent getting common data from database all the time.
- Prevent Unnecessary load/query.
- Use CDN
At the first place most of the server load rely on Sql and heavy query,
So instead of making multiple servers to handle request. You can do this
- Make Sql replica (Slave server) use it for reading and user master for writing.
- Use Memcache or Redis to prevent getting common data from database all the time.
- Prevent Unnecessary load/query.
- Use CDN
answered Nov 15 '18 at 9:41
Suraj TiwariSuraj Tiwari
1017
1017
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53316289%2floadbalancing-using-php-is-this-effective%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why not use nginx as a load balancer?
– Harvey Fletcher
Nov 15 '18 at 9:35
I know, but I just want to know if there is hypothetically any issue with doing this instead of using NGINX, as this is a much simpler method to implement.
– Destroyer
Nov 15 '18 at 9:36
2
Using a scripting language as a load balancer is going to be a lot slower, and is probably one of the most serious reinventing-the-wheel cases I can think of. But if you're doing it as a learning experiment, then good luck - there's no fundamental reason it can't be done.
– iainn
Nov 15 '18 at 9:37
@iainn What would be the effect of this if I am already using it in a fairly large website that get's tens of thousands of hits an hour?
– Destroyer
Nov 15 '18 at 9:40
1
@Destroyer Well if you're using an actual HTTP redirect rather than proxying the requests then the obvious drawback is that you won't be able to use anything other than GET requests. If you're using this for anything more complicated than serving basic static content then that might be a show-stopper straight away. I really, really wouldn't recommend using anything like this in production, let alone for a large website. Apache, nginx, haproxy, even DNS round-robin are going to be far more reliable.
– iainn
Nov 15 '18 at 9:41