0

定義した宛先にトラフィックを加重スケールで分散できるように、作成するすべてのリンクに加重ローテーターが必要です。現在、次のものを使用しています。

<?

header('Location: www.destinationwebsite1.com/index.php');

?>

ただし、これはトラフィックを 1 つのソースにのみ分散します。「重み」に基づいて、定義した多くの宛先に分散するものが必要です。

そのような:

25% to www.destinationwebsite1.com/index.php 
25% to www.destinationwebsite2.com/index.php 
25% to www.destinationwebsite3.com/index.php 
25% to www.destinationwebsite4.com/index.php 

または私が選択した割合。誰にもアイデアはありますか?

ベスト-N

4

2 に答える 2

1

random番号を使用し、それに基づいて結果を別の場所に送信します。

// equal weights:
$sites = Array(
     "http://www.example.com/",
     "http://google.com/",
     "http://youtube.com/"
);
header("Location: ".$sites[rand(0,count($sites)-1)]);

// individual weights:
$sites = Array(
     "http://www.example.com/" => 50,
     "http://google.com/" => 30,
     "http://youtube.com/" => 20
);
$rand = rand(0,array_sum($sites)-1);
foreach($sites as $site=>$weight) {
    $rand -= $weight;
    if( $rand < 0) break;
}
header("Location: ".$site);
于 2012-09-02T21:29:09.157 に答える
0

このようなもの?

<?php
$r = rand() / getrandmax();

if ( $r < 0.25 )
{
    header( 'Location: www.destinationwebsite1.com/index.php' );
}
elseif ( $r < 0.50 )
{
    header( 'Location: www.destinationwebsite2.com/index.php' );
}
elseif ( $r < 0.75 )
{
    header( 'Location: www.destinationwebsite3.com/index.php' );
}
else
{
    header( 'Location: www.destinationwebsite4.com/index.php' );
}

?>

これにより、統計的に各サイトへの訪問者の 25% が送信されるはずです。各サイトに送られる訪問者の割合を変更するには、重み付けの数値を変更するだけです。

于 2012-09-02T21:28:53.563 に答える