Finally commit ext for purging varnish on-demand
This commit is contained in:
		
							parent
							
								
									b47e4aacb1
								
							
						
					
					
						commit
						67628816a4
					
				
							
								
								
									
										38
									
								
								ext/varnish/main.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								ext/varnish/main.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | |||||||
|  | <?php | ||||||
|  | /* | ||||||
|  | * Name: Varnish Purger | ||||||
|  | * Author: Shish <webmaster@shishnet.org> | ||||||
|  | * License: GPLv2 | ||||||
|  | * Visibility: admin | ||||||
|  | * Description: Sends PURGE requests when a /post/view is updated | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | class VarnishPurger extends Extension { | ||||||
|  | 	private function curl_purge($path) { | ||||||
|  | 		$url = make_http(make_link($path)); | ||||||
|  | 		$ch = curl_init(); | ||||||
|  | 		curl_setopt($ch, CURLOPT_URL,$url); | ||||||
|  | 		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PURGE"); | ||||||
|  | 		$result = curl_exec($ch); | ||||||
|  | 		$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | ||||||
|  | 		curl_close($ch); | ||||||
|  | 		return $result; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function onCommentPosting(CommentPostingEvent $event) { | ||||||
|  | 		$this->curl_purge("post/view/{$event->image_id}"); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function onImageInfoSet(ImageInfoSetEvent $event) { | ||||||
|  | 		$this->curl_purge("post/view/{$event->image->id}"); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public function onImageDeletion(ImageDeletionEvent $event) { | ||||||
|  | 		$this->curl_purge("post/view/{$event->image->id}"); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * @return int | ||||||
|  | 	 */ | ||||||
|  | 	public function get_priority() {return 99;} | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user