Last active
February 8, 2016 23:00
-
-
Save jonnybarnes/3ca72a6a0f2b942efeeb to your computer and use it in GitHub Desktop.
Use arrays for slightly better caching in indieauth-client-php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace IndieAuth; | |
use BarnabyWalters\Mf2; | |
class Client { | |
private static $_headers = array(); //if you bump requirement to php5.4 we could use short syntax | |
private static $_body = array(); | |
//skip some code | |
private static function _fetchHead($url) { | |
if(array_key_exists($url, self::$_headers)) { | |
return self::$_headers[$url]; | |
} else { | |
$ch = curl_init($url); | |
self::_setUserAgent($ch); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_NOBODY, true); | |
self::$_headers[$url] = curl_exec($ch); | |
return self::$_headers[$url]; | |
} | |
} | |
private static function _fetchBody($url) { | |
if(array_key_exists($host, self::$_body)) { | |
return self::$_body[$url]; | |
} else { | |
$ch = curl_init($url); | |
self::_setUserAgent($ch); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
self::$_body[$url] = curl_exec($ch); | |
return self::$_body[$url]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment