jeremykendall / php-domain-parser

Public Suffix List based domain parsing implemented in PHP
MIT License
1.16k stars 128 forks source link

Pdp local cache location #257

Closed leem32 closed 4 years ago

leem32 commented 4 years ago

When I run ./update-psl from webroot it returns:

Updating your Pdp local cache.
Public Suffix List Cache updated for 1 DAY using https://publicsuffix.org/list/public_suffix_list.dat   
Updating your IANA Root Zone Database copy.                                                                                                                  
IANA Root Zone Database Cache updated for 1 DAY using https://data.iana.org/TLD/tlds-alpha-by-domain.txt
Pdp local cache successfully updated.

(I changed line 21 fromrequire dirname(__DIR__).'/vendor/autoload.php'; to require '/var/www/html/src/vendor/autoload.php';) because I was getting No such file or directory errors.

But I can't find the cache file. If I run ./update-psl -h it shows:

--cache-dir=CACHE-DIR set the cache root directory (default: /var/www/html/data')

But the default dir ( /var/www/html/data) does not exist.

Where can I find the updated pdp cache file and how do I know it's being used by php-domain-parser?

Here's how I'm running php-domain-parser:

require './vendor/autoload.php';

use League\Uri;
use Pdp\Cache;
use Pdp\CurlHttpClient;
use Pdp\Manager;
use Pdp\Rules;

$manager = new Manager(new Cache(), new CurlHttpClient(), '1 DAY');

$rules = $manager->getTLDs();

$url = 'https://www.example.com/en';
$components = Uri\UriString::parse($url);
$domain = $rules->resolve($components['host']);

if ($domain->isICANN()) {
    echo $domain->getContent() . "\n\n";
    echo $domain->getPublicSuffix() . "\n\n";
    echo $domain->getRegistrableDomain() . "\n\n";
    echo $domain->getSubDomain() . "\n\n";
}

Also does the 1 DAY in $manager = new Manager(new Cache(), new CurlHttpClient(), '1 DAY'); ensure the PSL is only cached for 1 day? I couldn't find anything on this in the docs, but found an example in an issue.

nyamsprod commented 4 years ago

@leem32 thanks for using the library.

Where can I find the updated pdp cache file and how do I know it's being used by php-domain-parser?

The default location is in your vendor directory inside the package data directory. This is where the cache is set by default. and this is where it is updated unless you changed your configuration and which case it depends how you've setup it up.

Also does the 1 DAY in $manager = new Manager(new Cache(), new CurlHttpClient(), '1 DAY'); ensure the PSL is only cached for 1 day?

Indeed it is not documented in the README (you can submit a PR for that) but it is documented in the CHANGELOG . This parameter was added in version 5.4.0 to improve PSR-16 compatibility. And yes this is a TTL on the data cache before it is refreshed unless you do it yourself before the end of the TTL.

leem32 commented 4 years ago

Thanks :)

I think the easiest way to keep the PSL updated is with a cronjob. 27 5 * * * cd /var/www/html && ./update-psl > /dev/null 2>&1

nyamsprod commented 4 years ago

a cronjob and another cache system not related to your production server filesystem using the PSR-16 compatible contract