Two servers for one site

Discussion in 'PHP' started by mehdiali, Dec 24, 2007.

  1. #1
    Hi everyone
    imagine:
    i have a site and two servers that one of them is located (for example)
    in New York city and other one in Washington.
    I want to download some pages of site from New York server
    and other ones from Washington server.
    how can i do this ?
    Thank you in advance.
     
    mehdiali, Dec 24, 2007 IP
  2. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you talking about load balancing?

    As in you want half your users to use the New York server and the other half to use the Washington server?
     
    tonybogs, Dec 25, 2007 IP
  3. mehdiali

    mehdiali Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No tonybogs ,
    the contents of the site (pages) divide into two sections.
    one section is on New York server and other one is on Washington server.
    in fact when the user wants to visit the site, some pages download from New York and other ones download from Washington.
     
    mehdiali, Dec 25, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    You can do two things:

    * User different domains, aka: www.domain.com , domain.com
    * Use IP address of server instead of domain name

    Peace,
     
    Barti1987, Dec 25, 2007 IP
  5. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You could also take this approach, use 2 servers:

    www.domain1.com (new york)
    www.domain2.com (washington)

    Use domain1 server as the master, all incoming requests go to this server. If a page example.php is requested on domain1 you can just include the file via http from domain2.

    <?php
    include('http://www.domain2.com/example.php');
    ?>

    If you are handling all incomiong requests through 1 file like index.php this should be easy as all you'll need to do is check if the file exists. If it doesnt include it from server 2.

    As a note though, this will only work if you have allow_url_fopen enabled in your config.

    Hope this helps
     
    tonybogs, Dec 25, 2007 IP
  6. bfellow

    bfellow Active Member

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #6
    If at all possible, I would avoid this scenario like the plague. While tonybogs example will definitely work, I am having a very hard time seeing why you would want to set up your boxes like this. I guess if you have content that is owned by someone else that resides on there box and you need access to it. If you have the choice, mirror the two boxes. If one box fries, then you are not out half your content! It would be a matter of buying a new box and mirroring back your site image. You don't want to set up a true master/slave setup either. There is no need to be constantly bouncing traffic up and down the Eastern seaboard. Remember that this will only add to bandwidth costs. Go with load balancing. Best way to go. Two mirrored boxes for redundancy and a load balancer. If you have the money, check out F5 Networks. They make some great stuff. Plus after the dot.bomb, you can get surplus stuff on eBay dirt cheap (like 90%+ off!).

    Good luck with your project!
     
    bfellow, Dec 26, 2007 IP
  7. mehdiali

    mehdiali Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thank you tonybogs for your suggestion(including),
    but i'm sorry,
    my question was changed(just a little) because it is my friend's question.
    i said "some pages" but in fact "some files" like jpg,exe,rar and etc.must download from Washington server and other ones from New York server.it is an upload center.
    for example :
    mehdiali/files/a.exe (it is downloaded from Washington server)
    mehdiali/files/b.exe (it is downloaded from New York server)

    what is your idea about using .htaccess(it is a file that locate in folder in apache and you can write some commands. and according them apache do
    something).
    or
    is there any tools in operating systems that if there isn't requseted file in
    one of them send a message(request) to another operating system and get it.
     
    mehdiali, Dec 29, 2007 IP
  8. getit

    getit Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I have website which provides free mobile stuff. Site is full of downloadable contents. In situations of too many simultaneous
    request from visitors, my visitors face either broken download or page unavailable.
    So i decided to share server load into two servers.
    Now i purchased two hosting accounts from different companies and uploded all data on both servers. Now i have one website name and two different dedicated IPs. Now problem is that i want to share load between two servers. If there are two simultaneous requests it should be handled one by server A and second by server B.
    I dont have enough knowledge to configure load balancing between two servers for my site.
    Kindly write down complete procedure.
    Thanks in advance.
     
    getit, Dec 30, 2007 IP
  9. Adwords.

    Adwords. Banned

    Messages:
    518
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #9
    host all images/content on server 1/domain 1

    have all pages/etc with hotlinked content on server 2 ( hotlinked content is on server 1 )
     
    Adwords., Dec 30, 2007 IP
  10. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    maybe create a session table, and redirect session alternately?
     
    kendo1979, Dec 30, 2007 IP
  11. mehdiali

    mehdiali Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    1. Last news : I don't know name of the files.
    2.I got something from http://www.thephpforum.net :
    set this in your .htaccess

    ---------Start----------
    # to make exe force to download
    AddType application/octet-stream .exe

    #redirect your request to paticular server
    Redirect 301 /files/a.exe http://Washingtonserver-path/a.exe
    Redirect 301 /files/b.exe http://NeWYorkserver-path/b.exe
    -----------End---------

    place the .htaccess file your both server


    _________________
    Thanks,
    Muthukumar Selvarasu,
    Project Manager,
    Webmasters Ltd.

    3. but because i don't know the name of files
    i can't use it.
    if you can change it as i can use it please send your suggest.
    4. joebert, a member of apache forum of own site :
    Your best bet will be asking in relevant OS forums about setting up network shares on server B so server A can setup aliases & treat those server B shares like directories. Then you can either setup a download script that checks the current location followed by the remote location for each request, or setup a 404 script that checks the remote location only in the event the current location doesn't have the file.
    5. when we use 404 script , it redirect www.mehdiali/files/b.exe to another server
    without files/b.exe so b.exe will not download.
     
    mehdiali, Dec 31, 2007 IP
  12. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #12
    use sub domains dude

    example

    server1.yoursite.com
    server2.yoursite.com
     
    PowerExtreme, Dec 31, 2007 IP
  13. Dygital

    Dygital Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Since you're dealing with media content, it may prove beneficial to use a CDN. A CDN will automatically use GeoIPLocation to select the right server for your visitors. Although CDNs do cost money to use (usually per GB/TB transfer), they really offer high speed for your premium users.

    A Google search for Content Delivery Network will prove useful for this purpose:
    http://www.google.com/search?hl=en&q=Content+delivery+network&btnG=Search


    This is very possible, too. All you need to do is specify static routes to these servers. :)

    ~Joe
     
    Dygital, Dec 31, 2007 IP
  14. msaqibansari

    msaqibansari Peon

    Messages:
    84
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    its simple.

    just bind content with server in .htaccess file.

    I've already done this for my client.
     
    msaqibansari, Jan 1, 2008 IP
  15. mehdiali

    mehdiali Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    thank you for your replies,
    the solution :
    the user type mehdiali/files/b.exe(requested_url) that isn't available in server A.
    so i must redirect it to server B.
    i write a command like this in htaccess file :

    ErrorDocument 404 "http://localhost/divider.php?r_u=requested_url"

    so in divider.php page i have $HTTP_GET_VARS['r_u']
    and after fetching the b.exe(file name)
    i'll redirect it to server B, like this :
    header("location:mehdiali2/filename/b.exe");

    but my problem is how i can find requested_url.
    what do you write instead of requested_url in
    ErrorDocument 404 "http://localhost/divider.php?r_u=requested_url"
    is there any variable?

    i don't know the name of the files.
    please send the complete code.
     
    mehdiali, Jan 1, 2008 IP
  16. hba

    hba Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    hi
    thanx mehdi :eek:
    i use this code in htaccess to redirect with all request url
    
    ewriteEngine On
    RewriteRule upload/(.*)$ http://server2.com/upload/$1 [L]
    
    Code (markup):
    but i think we can use this code when 404 error return
     
    hba, Jan 2, 2008 IP
  17. mehdiali

    mehdiali Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    the code redirects http://A/files/b.exe to http://B/files/b.exe if b.exe
    is not in server A
    type this code in your htaccess file :

    ErrorDocument 404
    "<html><body>
    <script language =javascript>
    url= window.location;<!--current URL
    url = url+'';<!--convert it's type to string
    slash_location=0;
    <!--this while is using for extracting the file name
    <!--i mean : http://A/files/b.exe that isn't in server A
    while(slash_location!=-1)
    {
    end_slash_location= url.search('/');
    url=url.substring(end_slash_location+1,url.length);
    slash_location=url.search('/');
    }
    <!--here value of URL is b.exe
    window.location='http://B/files/'+url; <!--redirect it to server B
    </script>
    </body></html>"

    Note:
    1.ErrorDocument 404 command:
    ErrorDocument 404 is a event that arise when "Page can't be displayed"
    and then the command is executed.
    2.all of the mentioned code must be in one line.
    3.ErrorDocument 404 " you can't use double quotation in this area ".
    4.the script must locate just in one of the servers(in this case in server A).
     
    mehdiali, Jan 2, 2008 IP