Last active
January 19, 2017 10:45
-
-
Save bogdanr/2c5297167776bdfe01b624b62749558d to your computer and use it in GitHub Desktop.
Purge web article from PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment