[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2022 The s9e authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Utils\Http\Clients; 9 10 use s9e\TextFormatter\Utils\Http\Client; 11 12 class Curl extends Client 13 { 14 /** 15 * @var resource cURL handle, shared across instances 16 */ 17 protected static $handle; 18 19 /** 20 * {@inheritdoc} 21 */ 22 public function get($url, array $options = []) 23 { 24 $options += ['headers' => []]; 25 26 $handle = $this->getHandle(); 27 curl_setopt($handle, CURLOPT_HEADER, !empty($options['returnHeaders'])); 28 curl_setopt($handle, CURLOPT_HTTPGET, true); 29 curl_setopt($handle, CURLOPT_HTTPHEADER, $options['headers']); 30 curl_setopt($handle, CURLOPT_URL, $url); 31 32 return curl_exec($handle); 33 } 34 35 /** 36 * {@inheritdoc} 37 */ 38 public function post($url, array $options = [], $body = '') 39 { 40 $options += ['headers' => []]; 41 $options['headers'][] = 'Content-Length: ' . strlen($body); 42 43 $handle = $this->getHandle(); 44 curl_setopt($handle, CURLOPT_HEADER, !empty($options['returnHeaders'])); 45 curl_setopt($handle, CURLOPT_HTTPHEADER, $options['headers']); 46 curl_setopt($handle, CURLOPT_POST, true); 47 curl_setopt($handle, CURLOPT_POSTFIELDS, $body); 48 curl_setopt($handle, CURLOPT_URL, $url); 49 50 return curl_exec($handle); 51 } 52 53 /** 54 * Return a globally cached cURL handle, configured for current instance 55 * 56 * @return resource 57 */ 58 protected function getHandle() 59 { 60 if (!isset(self::$handle)) 61 { 62 self::$handle = $this->getNewHandle(); 63 } 64 65 curl_setopt(self::$handle, CURLOPT_SSL_VERIFYPEER, $this->sslVerifyPeer); 66 curl_setopt(self::$handle, CURLOPT_TIMEOUT, $this->timeout); 67 68 return self::$handle; 69 } 70 71 /** 72 * Create and return a new cURL handle 73 * 74 * @return resource 75 */ 76 protected function getNewHandle() 77 { 78 $handle = curl_init(); 79 curl_setopt($handle, CURLOPT_ENCODING, ''); 80 curl_setopt($handle, CURLOPT_FAILONERROR, true); 81 curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); 82 curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); 83 84 return $handle; 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |