0

ok, so i been on a mental struggle here trying to get this completed.

I have an array that looks like

Array ( [0] => cluster_1 [1] => cluster_2 )

I want to add a new user to the first available cluster that has sufficient space to allocated the new user.

I have this class method created to output the amount of megs in each array item. I can test it out and echo the results with

foreach ($cluster_array as $cluster) {
    echo $cluster . " " . Server::server_free_space("/agents/" . $cluster, 2)."<br />";
}

the output gives me

cluster_1 20505
cluster_2 21398

those figures are in MB.

I want to have my array looped to find the first available cluster that has enough space to allocate a new user. For example if a new user needs 1gb allocated, thats 1024mb. So if the first cluster in the array does not have 1024MB free, then it will move and scan the next cluster in the array and so on. Adding the user to that cluster.

How would I approach this?

2 Answers 2

1

Shouldn't it be just:

foreach ($cluster_array as $cluster) {
    $size =  Server::server_free_space("/agents/" . $cluster, 2);
    if($size >= $whatTheUserNeeds) {
        // add user to cluster
        break;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0
$space_required_for_new_user = 1024
foreach ($cluster_array as $cluster) {
    $free_space = Server::server_free_space("/agents/" . $cluster, 2);
    if($free_space >= $space_required_for_new_user) {
        //add new user
        break; //will not continue through the loop
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.