public $force_cache_fallback = false;
* @var int Cache duration (in seconds)
* @see SimplePie::set_cache_duration()
public $cache_duration = 3600;
* @var int Auto-discovery cache duration (in seconds)
* @see SimplePie::set_autodiscovery_cache_duration()
public $autodiscovery_cache_duration = 604800; // 7 Days.
* @var string Cache location (relative to executing script)
* @see SimplePie::set_cache_location()
public $cache_location = './cache';
* @var string&(callable(string): string) Function that creates the cache filename
* @see SimplePie::set_cache_name_function()
public $cache_name_function = 'md5';
* @var bool Reorder feed by date descending
* @see SimplePie::enable_order_by_date()
public $order_by_date = true;
* @var mixed Force input encoding to be set to the follow value
* (false, or anything type-cast to false, disables this feature)
* @see SimplePie::set_input_encoding()
public $input_encoding = false;
* @var self::LOCATOR_* Feed Autodiscovery Level
* @see SimplePie::set_autodiscovery_level()
public $autodiscovery = self::LOCATOR_ALL;
* @var int Maximum number of feeds to check with autodiscovery
* @see SimplePie::set_max_checked_feeds()
public $max_checked_feeds = 10;
* @var array<Response>|null All the feeds found during the autodiscovery process
* @see SimplePie::get_all_discovered_feeds()
public $all_discovered_feeds = [];
* @var string Web-accessible path to the handler_image.php file.
* @see SimplePie::set_image_handler()
public $image_handler = '';
* @var array<string> Stores the URLs when multiple feeds are being initialized.
* @see SimplePie::set_feed_url()
public $multifeed_url = [];
* @var array<int, static> Stores SimplePie objects when multiple feeds initialized.
public $multifeed_objects = [];
* @var array<mixed> Stores the get_object_vars() array for use with multifeeds.
* @see SimplePie::set_feed_url()
public $config_settings = null;
* @var int Stores the number of items to return per-feed with multifeeds.
* @see SimplePie::set_item_limit()
* @var bool Stores if last-modified and/or etag headers were sent with the
* request when checking a feed.
public $check_modified = false;
* @var array<string> Stores the default attributes to be stripped by strip_attributes().
* @see SimplePie::strip_attributes()
public $strip_attributes = ['bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'];
* @var array<string, array<string, string>> Stores the default attributes to add to different tags by add_attributes().
* @see SimplePie::add_attributes()
public $add_attributes = ['audio' => ['preload' => 'none'], 'iframe' => ['sandbox' => 'allow-scripts allow-same-origin'], 'video' => ['preload' => 'none']];
* @var array<string> Stores the default tags to be stripped by strip_htmltags().
* @see SimplePie::strip_htmltags()
public $strip_htmltags = ['base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'];
* @var string[]|string Stores the default attributes to be renamed by rename_attributes().
* @see SimplePie::rename_attributes()
public $rename_attributes = [];
* @var bool Should we throw exceptions, or use the old-style error property?
public $enable_exceptions = false;
private $http_client = null;
/** @var bool Whether HTTP client has been injected */
private $http_client_injected = false;
* The SimplePie class contains feed level data and options
* To use SimplePie, create the SimplePie object with no parameters. You can
* then set configuration options using the provided methods. After setting
* them, you must initialise the feed using $feed->init(). At that point the
* object's methods and properties will be available to you.
* Previously, it was possible to pass in the feed URL along with cache
* options directly into the constructor. This has been removed as of 1.3 as
* it caused a lot of confusion.
* @since 1.0 Preview Release
public function __construct()
if (version_compare(PHP_VERSION, '7.2', '<')) {
exit('Please upgrade to PHP 7.2 or newer.');
$this->set_cache_namefilter(new CallableNameFilter($this->cache_name_function));
// Other objects, instances created here so we can set options on them
$this->sanitize = new Sanitize();
$this->registry = new Registry();
if (func_num_args() > 0) {
trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_duration() directly.', \E_USER_DEPRECATED);
$this->set_cache_duration($args[2]);
$this->set_cache_location($args[1]);
$this->set_feed_url($args[0]);
* Used for converting object to a string
public function __toString()
return md5(serialize($this->data));
* Remove items that link back to this before destroying this object
public function __destruct()
if (!empty($this->data['items'])) {
foreach ($this->data['items'] as $item) {
unset($item, $this->data['items']);
if (!empty($this->data['ordered_items'])) {
foreach ($this->data['ordered_items'] as $item) {
unset($item, $this->data['ordered_items']);
* Force the given data/URL to be treated as a feed
* This tells SimplePie to ignore the content-type provided by the server.
* Be careful when using this option, as it will also disable autodiscovery.
* @param bool $enable Force the given data/URL to be treated as a feed
public function force_feed(bool $enable = false)
$this->force_feed = $enable;
* Set the URL of the feed you want to parse
* This allows you to enter the URL of the feed you want to parse, or the
* website you want to try to use auto-discovery on. This takes priority
* Deprecated since 1.9.0: You can set multiple feeds to mash together by passing an array instead
* of a string for the $url. Remember that with each additional feed comes
* additional processing and resources.
* @since 1.0 Preview Release
* @param string|string[] $url This is the URL (or (deprecated) array of URLs) that you want to parse.
public function set_feed_url($url)
$this->multifeed_url = [];
trigger_error('Fetching multiple feeds with single SimplePie instance is deprecated since SimplePie 1.9.0, create one SimplePie instance per feed and use SimplePie::merge_items to get a single list of items.', \E_USER_DEPRECATED);
foreach ($url as $value) {
$this->multifeed_url[] = $this->registry->call(Misc::class, 'fix_protocol', [$value, 1]);
$this->feed_url = $this->registry->call(Misc::class, 'fix_protocol', [$url, 1]);
$this->permanent_url = $this->feed_url;
* Set an instance of {@see File} to use as a feed
* @deprecated since SimplePie 1.9.0, use \SimplePie\SimplePie::set_http_client() or \SimplePie\SimplePie::set_raw_data() instead.
* @return bool True on success, false on failure
public function set_file(File &$file)
// trigger_error(sprintf('SimplePie\SimplePie::set_file() is deprecated since SimplePie 1.9.0, please use "SimplePie\SimplePie::set_http_client()" or "SimplePie\SimplePie::set_raw_data()" instead.'), \E_USER_DEPRECATED);
$this->feed_url = $file->get_final_requested_uri();
$this->permanent_url = $this->feed_url;
* Set the raw XML data to parse
* Allows you to use a string of RSS/Atom data instead of a remote feed.
* If you have a feed available as a string in PHP, you can tell SimplePie
* to parse that data string instead of a remote feed. Any set feed URL
* @param string $data RSS or Atom data as a string.
public function set_raw_data(string $data)
* Set a PSR-18 client and PSR-17 factories
* Allows you to use your own HTTP client implementations.
* This will become required with SimplePie 2.0.0.
final public function set_http_client(
ClientInterface $http_client,
RequestFactoryInterface $request_factory,
UriFactoryInterface $uri_factory
$this->http_client = new Psr18Client($http_client, $request_factory, $uri_factory);
* Set the default timeout for fetching remote feeds
* This allows you to change the maximum time the feed's server to respond
* and send the feed back.
* @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
public function set_timeout(int $timeout = 10)
if ($this->http_client_injected) {
throw new SimplePieException(sprintf(
'Using "%s()" has no effect, because you already provided a HTTP client with "%s::set_http_client()". Configure timeout in your HTTP client instead.',
$this->timeout = (int) $timeout;
// Reset a possible existing FileClient,
// so a new client with the changed value will be created
if (is_object($this->http_client) && $this->http_client instanceof FileClient) {
$this->http_client = null;
} elseif (is_object($this->http_client)) {
// Trigger notice if a PSR-18 client was set
'Using "%s()" has no effect, because you already provided a HTTP client with "%s::set_http_client()". Configure the timeout in your HTTP client instead.',
* Set custom curl options
* This allows you to change default curl options
* @param array<int, mixed> $curl_options Curl options to add to default settings
public function set_curl_options(array $curl_options = [])
if ($this->http_client_injected) {
throw new SimplePieException(sprintf(
'Using "%s()" has no effect, because you already provided a HTTP client with "%s::set_http_client()". Configure custom curl options in your HTTP client instead.',
$this->curl_options = $curl_options;
// Reset a possible existing FileClient,
// so a new client with the changed value will be created
if (is_object($this->http_client) && $this->http_client instanceof FileClient) {
$this->http_client = null;
} elseif (is_object($this->http_client)) {
// Trigger notice if a PSR-18 client was set
'Using "%s()" has no effect, because you already provided a HTTP client with "%s::set_http_client()". Configure the curl options in your HTTP client instead.',
* Force SimplePie to use fsockopen() instead of cURL
* @param bool $enable Force fsockopen() to be used
public function force_fsockopen(bool $enable = false)
if ($this->http_client_injected) {
throw new SimplePieException(sprintf(
'Using "%s()" has no effect, because you already provided a HTTP client with "%s::set_http_client()". Configure fsockopen in your HTTP client instead.',
$this->force_fsockopen = $enable;
// Reset a possible existing FileClient,
// so a new client with the changed value will be created
if (is_object($this->http_client) && $this->http_client instanceof FileClient) {
$this->http_client = null;
} elseif (is_object($this->http_client)) {
// Trigger notice if a PSR-18 client was set
'Using "%s()" has no effect, because you already provided a HTTP client with "%s::set_http_client()". Configure fsockopen in your HTTP client instead.',
* Enable/disable caching in SimplePie.
* This option allows you to disable caching all-together in SimplePie.
* However, disabling the cache can lead to longer load times.
* @since 1.0 Preview Release
* @param bool $enable Enable caching
public function enable_cache(bool $enable = true)
$this->enable_cache = $enable;
* Set a PSR-16 implementation as cache
* @param CacheInterface $cache The PSR-16 cache implementation
public function set_cache(CacheInterface $cache)
$this->cache = new Psr16($cache);
* SimplePie to continue to fall back to expired cache, if enabled, when
* This tells SimplePie to ignore any file errors and fall back to cache
* instead. This only works if caching is enabled and cached content
* @deprecated since SimplePie 1.8.0, expired cache will not be used anymore.
* @param bool $enable Force use of cache on fail.
public function force_cache_fallback(bool $enable = false)
// @trigger_error(sprintf('SimplePie\SimplePie::force_cache_fallback() is deprecated since SimplePie 1.8.0, expired cache will not be used anymore.'), \E_USER_DEPRECATED);
$this->force_cache_fallback = $enable;
* Set the length of time (in seconds) that the contents of a feed will be
* @param int $seconds The feed content cache duration
public function set_cache_duration(int $seconds = 3600)
$this->cache_duration = $seconds;
* Set the length of time (in seconds) that the autodiscovered feed URL will
* @param int $seconds The autodiscovered feed URL cache duration.
public function set_autodiscovery_cache_duration(int $seconds = 604800)