├── .gitignore ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Facades └── Ping.php ├── Ping.php └── PingServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Karl Monson 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ping for Laravel 2 | 3 | This Laravel package is simple and unopinionated. It simply returns the HTTP Status Code for a provided URL. 4 | 5 | ## Installation 6 | 7 | Install via Composer: 8 | ```bash 9 | composer require karlmonson/laravel-ping 10 | ``` 11 | You'll need to register the ServiceProvider and Facade: 12 | ```php 13 | // config/app.php 14 | 15 | 'providers' => [ 16 | // ... 17 | Karlmonson\Ping\PingServiceProvider::class, 18 | ]; 19 | 20 | 'aliases' => [ 21 | // ... 22 | 'Ping' => Karlmonson\Ping\Facades\Ping::class, 23 | ]; 24 | ``` 25 | 26 | ## Usage 27 | 28 | ```php 29 | =6.0" 21 | }, 22 | "extra": { 23 | "laravel": { 24 | "providers": [ 25 | "Karlmonson\\Ping\\PingServiceProvider" 26 | ], 27 | "aliases": { 28 | "Ping": "Karlmonson\\Ping\\Facades\\Ping" 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Facades/Ping.php: -------------------------------------------------------------------------------- 1 | client = new Client([ 40 | 'timeout' => $this->timeout, 41 | 'allow_redirects' => $this->allowRedirects, 42 | ]); 43 | } 44 | 45 | public function check($url) 46 | { 47 | try { 48 | $response = $this->client->get($url); 49 | $this->responseCode = $response->getStatusCode(); 50 | } catch(ClientException $e) { 51 | $response = $e->getResponse(); 52 | $this->responseCode = $response->getStatusCode(); 53 | } catch(ConnectException $e) { 54 | $this->responseCode = $e->getCode(); 55 | } catch(ServerException $e) { 56 | $this->responseCode = $e->getCode(); 57 | } 58 | 59 | return $this->responseCode; 60 | } 61 | 62 | public function checkA($host, $val) 63 | { 64 | $this->dns = collect(dns_get_record($host, DNS_A)); 65 | $filtered = $this->dns->filter(function($item, $key) use($val) { 66 | return $item['ip'] == $val; 67 | }); 68 | return $filtered->count() > 0; 69 | } 70 | 71 | public function checkCname($host, $val) 72 | { 73 | $this->dns = collect(dns_get_record($host, DNS_CNAME)); 74 | $filtered = $this->dns->filter(function($item, $key) use($val) { 75 | return $item['target'] === $val; 76 | }); 77 | return $filtered->count() > 0; 78 | } 79 | 80 | public function checkNameserver($host, $val) 81 | { 82 | $this->dns = collect(dns_get_record($host, DNS_NS)); 83 | $filtered = $this->dns->filter(function($item, $key) use($val) { 84 | return $item['target'] === $val; 85 | }); 86 | return $filtered->count() > 0; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/PingServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton('ping', function ($app) { 24 | return new Ping(); 25 | }); 26 | } 27 | 28 | /** 29 | * Get the services provided by the provider. 30 | * 31 | * @return array 32 | */ 33 | public function provides() 34 | { 35 | return ['ping']; 36 | } 37 | } --------------------------------------------------------------------------------