Skip to content

Instantly share code, notes, and snippets.

@ilyasozkurt
Created Sep 24, 2021
Embed
What would you like to do?
<?php
//Change error mode to display all
error_reporting(E_ALL);
//Change error displaying mode on
ini_set('display_errors', 1);
//Include libraries which we installed with composer
require 'vendor/autoload.php';
//Parameters
$domain = 'https://epey.com/';
//Create a client for http requests
$client = new \GuzzleHttp\Client([
'base_uri' => $domain, //Set a base url before make requests
'timeout' => 3.0 //If there is no answer after x seconds stop waiting
]);
//Handle exceptions
try {
//Get response object from client
$response = $client->get('/');
//print http response code from response object
print $response->getBody()->getContents();
} catch (\GuzzleHttp\Exception\ConnectException $exception) {
//Print client exception if is there any error.
die('could not connect to host : ' . $exception->getMessage());
} catch (\GuzzleHttp\Exception\ClientException $exception) {
//Print client exception if is there any error.
die($exception->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment