--- layout: default title: PSL Manager redirect_from: - /publicsuffix/manager/ --- PSL Manager ======= ~~~php getRules('https://publicsuffix.org/list/public_suffix_list.dat'); $icann_rules->resolve('www.bébé.be'); ~~~ ## Refreshing the cached rules This method enables refreshing your local copy of the PSL ICANN Section stored with your [PSR-16](http://www.php-fig.org/psr/psr-16/) Cache and retrieved using the Http Client. By default the method will use the `ICANNSectionManager::PSL_URL` as the source URL but you are free to substitute this URL with your own. The method returns a boolean value which is `true` on success. ~~~php refreshRules('https://publicsuffix.org/list/public_suffix_list.dat'); ~~~ ## Automatic Updates It is important to always have an up to date PSL ICANN Section. In order to do so the library comes bundle with an auto-update script located in the `bin` directory. ~~~bash $ php ./bin/update-psl-icann-section ~~~ This script requires that: - The `League\Uri\Installer\ICANNSection` class which comes bundle with this package - The use of the Cache and HTTP Client implementations bundle with the package. If you prefer using your own implementations you should: 1. Copy the `League\Uri\Installer\ICANNSection` class 2. Adapt its code to reflect your requirements. In any cases your are required to register a cron with your chosen script to keep your data up to date For example, below I'm using the `ICANNSectionManager` with - the [Symfony Cache component](https://github.com/symfony/cache) - the [Guzzle](https://github.com/guzzle/guzzle) client. Of course you can add more setups depending on your usage.

Be sure to adapt the following code to your own framework/situation. The following code is given as an example without warranty of it working out of the box.

~~~php client = $client; } public function getContent(string $url): string { try { return $client->get($url)->getBody()->getContents(); } catch (Throwable $e) { throw new HttpClientException($e->getMessage(), $e->getCode(), $e); } } } $dbh = new PDO('mysql:dbname=testdb;host=127.0.0.1', 'dbuser', 'dbpass'); $symfonyCache = new PDOCache($dbh, 'league-psl-icann', 86400); $guzzleAdapter = new GuzzleHttpClientAdapter(new GuzzleClient()); $manager = new ICANNSectionManager($symfonyCache, $guzzleAdapter); $manager->refreshRules(); //the rules are saved to the database for 1 day //the rules are fetched using GuzzlClient $icann_rules = $manager->getRules(); $domain = $icann_rules->resolve('nl.shop.bébé.faketld'); $domain->getDomain(); //returns 'nl.shop.bébé.faketld' $domain->getPublicSuffix(); //returns 'faketld' $domain->getRegistrableDomain(); //returns 'bébé.faketld' $domain->getSubDomain(); //returns 'nl.shop' $domain->isValid(); //returns false ~~~ In any case, you should setup a cron to regularly update your local cache.