Exemple #1
0
 /**
  * Get HTTP status code for URL
  * @param string $url The remote URL
  * @return int The HTTP status code
  */
 protected function getStatusCodeForUrl($url)
 {
     $httpResponse = $this->httpClient->options($url);
     return $httpResponse->getStatusCode();
 }
Exemple #2
0
 /**
  * Sends a options request
  * @param string $uri
  * @param array $options Array such as
  *              'body' => [
  *                  'field' => 'abc',
  *                  'other_field' => '123',
  *                  'file_name' => fopen('/path/to/file', 'r'),
  *              ],
  *              'headers' => [
  *                  'foo' => 'bar',
  *              ],
  *              'cookies' => ['
  *                  'foo' => 'bar',
  *              ],
  *              'allow_redirects' => [
  *                   'max'       => 10,  // allow at most 10 redirects.
  *                   'strict'    => true,     // use "strict" RFC compliant redirects.
  *                   'referer'   => true,     // add a Referer header
  *                   'protocols' => ['https'] // only allow https URLs
  *              ],
  *              'save_to' => '/path/to/file', // save to a file or a stream
  *              'verify' => true, // bool or string to CA file
  *              'debug' => true,
  *              'timeout' => 5,
  * @return Response
  * @throws \Exception If the request could not get completed
  */
 public function options($uri, array $options = [])
 {
     $response = $this->client->options($uri, $options);
     return new Response($response);
 }
Exemple #3
0
<?php

/**
 * Created by PhpStorm.
 * User: raynald
 * Date: 4/16/15
 * Time: 10:00 AM
 */
// URL scanner app
// 1. Use Composer autoloader
require 'vendor/autoload.php';
use League\Csv\Reader;
use GuzzleHttp\Client;
// 2. Instantiate Guzzle HTTP client
$client = new Client();
// 3. Open and iterate CSV
// $csv = new \League\Csv\Reader($argv[1]);
$csv = Reader::createFromPath($argv[1]);
foreach ($csv as $url) {
    try {
        // 4. Send HTTP OPTIONS request
        $httpResponse = $client->options($url[0]);
        // 5. Inspect HTTP response status code
        if ($httpResponse->getStatusCode() >= 400) {
            throw new \Exception();
        }
    } catch (\Exception $e) {
        // 6. Print bad URL to standard out
        echo $url[0] . PHP_EOL;
    }
}