Skip to content

Instantly share code, notes, and snippets.

@jonnybarnes
Last active February 8, 2016 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonnybarnes/3ca72a6a0f2b942efeeb to your computer and use it in GitHub Desktop.
Save jonnybarnes/3ca72a6a0f2b942efeeb to your computer and use it in GitHub Desktop.
Use arrays for slightly better caching in indieauth-client-php
<?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