public static function verify($url, $caDir)
    {
        static $hostsByDir = [];
        
        if (!isset($hostsByDir[$caDir])) {
            $hostsByDir[$caDir] = [];
        }
        
        $extensions = ['crt', 'pem', 'cer', 'der'];
        
        // Must be https
        if (substr($url, 0, 5) != 'https') {
            return false;
        }
        
        // Default
        $defaultCA = $caDir . 'curl-ca-bundle.crt';
        
        // Look for a host specific CA file
        $host = strtolower(parse_url($url, PHP_URL_HOST));
        if (!$host) {
            return $defaultCA;
        }
        
        if (array_key_exists($host, $hostsByDir[$caDir])) {
            return $hostsByDir[$caDir][$host];
        }
        
        $filename = $host;
        do {
            // Look for the possible extensions
            foreach ($extensions as $ext) {
                if (file_exists($verify = $caDir . $filename . '.' . $ext)) {
                    $hostsByDir[$caDir][$host] = $verify;
                    return $verify;
                }
            }
            
            // Remove a subdomain each time
            $filename = substr($filename, strpos($filename, '.') + 1);
        } while (substr_count($filename, '.') > 0);
        
        // No specific match
        $hostsByDir[$caDir][$host] = $defaultCA;
        return $defaultCA;
    }