//curl_setopt_array($curl, $curlOptionList); //curl_exec($curl); //curl_close($curl); $fd = false; if ($debug == true) { print "\n---- Purge Output -----\n"; $fd = fopen("php://output", 'w+'); $curlOptionList[CURLOPT_VERBOSE] = true; $curlOptionList[CURLOPT_STDERR] = $fd; } $curlHandler = curl_init(); curl_setopt_array($curlHandler, $curlOptionList); curl_exec($curlHandler); curl_close($curlHandler); if ($fd !== false) { fclose($fd); } } if (!empty($_POST['urlpurge']) && !empty($_POST['domainpurge'])) { $url_purge = $_POST['urlpurge']; $domain_purge = $_POST['domainpurge']; // This is the array of ip addresses for each varnish server you want to receive the purge request $ip_array = array("10.0.0.1", "10.0.0.2", "10.0.0.3"); $URL = xss_cleaner($url_purge); $host_name = xss_cleaner($domain_purge); $debug = true; print "Updating the article in the database ...\n"; foreach ($ip_array as &$ipaddress) { purgeURL($host_name, $ipaddress, $URL, $debug); } }
<?php header('Content-Type: text/plain'); header('Cache-Control: max-age=0'); $hostname = 'localhost'; $port = 80; $URL = '/article.php'; $debug = true; print "Updating the article in the database ...\n"; purgeURL($hostname, $port, $URL, $debug); function purgeURL($hostname, $port, $purgeURL, $debug) { $finalURL = sprintf("http://%s:%d%s", $hostname, $port, $purgeURL); print "Purging {$finalURL}\n"; $curlOptionList = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => 'PURGE', CURLOPT_HEADER => true, CURLOPT_NOBODY => true, CURLOPT_URL => $finalURL, CURLOPT_CONNECTTIMEOUT_MS => 2000); $fd = false; if ($debug == true) { print "\n---- Curl debug -----\n"; $fd = fopen("php://output", 'w+'); $curlOptionList[CURLOPT_VERBOSE] = true; $curlOptionList[CURLOPT_STDERR] = $fd; } $curlHandler = curl_init(); curl_setopt_array($curlHandler, $curlOptionList); curl_exec($curlHandler); curl_close($curlHandler); if ($fd !== false) { fclose($fd); } }