$hosts_to_add_to_vcl .= "backend {$name} {\n\t.host = \"{$ip}\";\n\t.port = \"80\";\n\t.probe = {.url = \"{$probe_file}\";.timeout = 1s;.interval = 5s;.window = 1;.threshold = 1;}\n}\n";
}
$hosts_to_add_to_vcl .= "sub vcl_init {\n\tnew cluster1 = directors.round_robin();\n";
foreach ($apaches as $name => $ip) {
    $hosts_to_add_to_vcl .= "\tcluster1.add_backend({$name});\n";
}
$hosts_to_add_to_vcl .= "}\n";
$hosts_to_add_to_vcl .= "sub vcl_recv {set req.backend_hint = cluster1.backend();}\n";
$new_vcl = "";
foreach ($vcl as $line) {
    $new_vcl .= "{$line}\n";
    if ($line == "#AUTOGENERATED_START") {
        $new_vcl .= $hosts_to_add_to_vcl;
    }
}
// send the new VCL
$vcl_name = "autogenated" . time();
$varnish->vcl_inline($vcl_name, $new_vcl);
sleep(1);
$varnish->vcl_use($vcl_name);
// remove all VCL exept the last one
$vcls = $varnish->vcl_list();
if ($vcls["code"] == Nexcessnet_Turpentine_Model_Varnish_Admin_Socket::CODE_OK) {
    $vcls = explode("\n", trim($vcls["text"]));
    array_pop($vcls);
    foreach ($vcls as $vcl_to_remove) {
        $vcl_to_remove = explode(" ", $vcl_to_remove);
        $vcl_to_remove = $vcl_to_remove[sizeof($vcl_to_remove) - 1];
        $varnish->vcl_discard($vcl_to_remove);
    }
}