@@ -50,6 +50,45 @@ public function __construct (
50
50
$ this ->_urlFinder = $ urlFinder ;
51
51
}
52
52
53
+ /**
54
+ * This method simply traverses all the configured Varnish servers and attempts to connect with
55
+ * them. If they are ALL healthy then an empty array is returned.
56
+ * @return array Collection of errors
57
+ */
58
+ public function isConfiguredServersHealthy () {
59
+ // Collection of messages
60
+ $ responses = [];
61
+ // Traverse through all the configured servers
62
+ foreach ( $ this ->_data ->getVarnishServersWithPorts () as $ varnishServer ) {
63
+ // Initialize a curl object
64
+ $ handle = curl_init ( $ varnishServer ->host );
65
+ // Set curl options
66
+ curl_setopt ( $ handle , CURLOPT_PORT , $ varnishServer ->port );
67
+ curl_setopt ( $ handle , CURLOPT_FOLLOWLOCATION , true );
68
+ curl_setopt ( $ handle , CURLOPT_RETURNTRANSFER , false );
69
+ curl_setopt ( $ handle , CURLOPT_AUTOREFERER , true );
70
+ curl_setopt ( $ handle , CURLOPT_HEADER , true );
71
+ curl_setopt ( $ handle , CURLOPT_CONNECTTIMEOUT , 3 );
72
+ curl_setopt ( $ handle , CURLOPT_TIMEOUT , 3 );
73
+ curl_setopt ( $ handle , CURLOPT_MAXREDIRS , 3 );
74
+ curl_setopt ( $ handle , CURLOPT_CUSTOMREQUEST , "HEAD " );
75
+ // Execute curl request and save response code
76
+ $ response = curl_exec ( $ handle );
77
+ $ responseCode = curl_getinfo ( $ handle , CURLINFO_HTTP_CODE );
78
+ // Close curl request using handle and return response code
79
+ curl_close ( $ handle );
80
+ // Return unhealthy if unreachable
81
+ if ( $ responseCode === 0 ) {
82
+ array_push (
83
+ $ responses ,
84
+ $ varnishServer ->host . ": " . $ varnishServer ->port
85
+ );
86
+ }
87
+ }
88
+ // Return error responses
89
+ return $ responses ;
90
+ }
91
+
53
92
/**
54
93
* This is a helper method that helps resolve url rewrites. It looks for all url rewrites with a
55
94
* given target path. It then uses this target path to find all request paths that lead to said
@@ -98,9 +137,9 @@ private function _purge ( $url, $additionalHeaders = [] ) {
98
137
curl_setopt ( $ handle , CURLOPT_RETURNTRANSFER , true );
99
138
curl_setopt ( $ handle , CURLOPT_AUTOREFERER , true );
100
139
curl_setopt ( $ handle , CURLOPT_HEADER , true );
101
- curl_setopt ( $ handle , CURLOPT_CONNECTTIMEOUT , 120 );
102
- curl_setopt ( $ handle , CURLOPT_TIMEOUT , 120 );
103
- curl_setopt ( $ handle , CURLOPT_MAXREDIRS , 10 );
140
+ curl_setopt ( $ handle , CURLOPT_CONNECTTIMEOUT , 10 );
141
+ curl_setopt ( $ handle , CURLOPT_TIMEOUT , 10 );
142
+ curl_setopt ( $ handle , CURLOPT_MAXREDIRS , 3 );
104
143
curl_setopt ( $ handle , CURLOPT_CUSTOMREQUEST , "PURGE " );
105
144
curl_setopt ( $ handle , CURLOPT_HTTPHEADER , $ additionalHeaders );
106
145
// Execute curl request and save response code
0 commit comments