PHP Round Robin

Discussion in 'PHP' started by jruyle, Mar 17, 2008.

  1. #1
    I'm going to be hosting a video very soon that will be viewed pretty widely. I'm concerned that my host may not be able to handle the entire load for the video and wanted to know if there was a way in PHP to do an IF / ELSE statement.

    I would like to do something like:

    IF file is online, display fileA
    ELSE display fileB

    But I'm not sure how I can send in information to test if the connection is "online".
     
    jruyle, Mar 17, 2008 IP
  2. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can't you host the video with youtube, set it as private so no one can access it. Then use the code that they provide to embed it into your website?
     
    imvain2, Mar 17, 2008 IP
  3. Adwords.

    Adwords. Banned

    Messages:
    518
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Easy. I can do it if you want for pretty cheap.

    Use:
    <?
    $status = $row['status'];
    $source = $row['source'];
    $source2 = $row['source2'];

    if ( $status == 1 ) {
    echo "<embedcode123>$source</embedcode123>";
    } else {
    echo "<embedcode123>$source2</embedcode123>";
    }

    ?>
     
    Adwords., Mar 17, 2008 IP
  4. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #4
    Adwords is talkin about database ..

    If youre gonna have that many peoples, i agree with the imvain2.
    YouTube would be capable of handling that kinda bandwidth.

    and like he said, set it to private so that nobody on YouTube can see it there.
    Then grab the <embed> source code they give ya ..and put that on your site.

    That way people coming to your site, still see the video on your site. but all bandwidth drain been routed to YouTube. - they like that probably. lol
     
    ezprint2008, Mar 18, 2008 IP
  5. jruyle

    jruyle Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Found/Figured something out, here is a brief snippet:

    
    <?php
    $url=("http://localhost/nameoffile.swf");
    $file=@fopen($url, "r");
    
        if ($file)
        {
            print("File available");
        }
        else
        {
            print("File not available");
        }
    
    
    fclose($fp);
    ?>
    
    PHP:
    It should be pretty easy from here. This snippet could be converted into other features such as cron job.
     
    jruyle, Mar 18, 2008 IP
  6. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    So this PHP file is on a server other than the one that is serving the video?

    You could use CURL to test if the URL returns a status 200 code.
     
    Gordaen, Mar 20, 2008 IP