Overview

Namespaces

  • Magyarjeti
    • Loripsum
      • Http
  • PHP

Classes

  • CurlAdapter

Interfaces

  • AdapterInterface
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Magyarjeti\Loripsum\Http;
 4: 
 5: /**
 6:  * Curl based HTTP adapter.
 7:  */
 8: class CurlAdapter implements AdapterInterface
 9: {
10:     /**
11:      * @var integer Connection timeout.
12:      */
13:     public $timeout = 5;
14: 
15:     /**
16:      * Make a HTTP request.
17:      *
18:      * @param string $url
19:      * @return string Response body.
20:      * @throws \RuntimeException
21:      */
22:     public function request($url)
23:     {
24:         $ch = curl_init();
25: 
26:         curl_setopt($ch, CURLOPT_URL, $url);
27:         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
28:         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
29: 
30:         $response = curl_exec($ch);
31: 
32:         curl_close($ch);
33: 
34:         if ($response === false) {
35:             throw new \RuntimeException('Connection timeout.');
36:         }
37: 
38:         return $response;
39:     }
40: }
41: 
API documentation generated by ApiGen