ReverseProxy.php
38 lines
| 1 | <?php |
| 2 | namespace NitroPack\SDK\Integrations; |
| 3 | use \NitroPack\HttpClient; |
| 4 | use \NitroPack\HttpClientMulti; |
| 5 | |
| 6 | class ReverseProxy { |
| 7 | |
| 8 | protected $serverList; |
| 9 | protected $purgeMethod; |
| 10 | |
| 11 | public function __construct($serverList=null, $purgeMethod="PURGE") { |
| 12 | $this->serverList = $serverList; |
| 13 | $this->purgeMethod = $purgeMethod; |
| 14 | } |
| 15 | |
| 16 | public function setServerList($serverList=null) { |
| 17 | $this->serverList = $serverList; |
| 18 | } |
| 19 | |
| 20 | public function setPurgeMethod($method) { |
| 21 | $this->purgeMethod = $method; |
| 22 | } |
| 23 | |
| 24 | public function purge($url) { |
| 25 | if (empty($this->serverList)) return false; |
| 26 | |
| 27 | $httpMulti = new HttpClientMulti(); |
| 28 | foreach ($this->serverList as $server) { |
| 29 | $client = new HttpClient($url); |
| 30 | $client->hostOverride($client->host, $server); |
| 31 | $client->doNotDownload = true; |
| 32 | $httpMulti->push($client); |
| 33 | } |
| 34 | |
| 35 | $httpMulti->fetchAll(true, $this->purgeMethod); |
| 36 | } |
| 37 | } |
| 38 |