Skip to content

Commit

Permalink
Merge pull request #6 from flownative/5-adjust-sitemap-crawler-for-php-8
Browse files Browse the repository at this point in the history
Adjust sitemap-crawler to PHP 8
  • Loading branch information
robertlemke committed Dec 16, 2022
2 parents 3db8a5d + da8da90 commit 7e2d31d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions root-files/opt/flownative/sitemap-crawler/sitemap-crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* (c) Robert Lemke, Flownative GmbH - www.flownative.com
*/

if (PHP_MAJOR_VERSION >= 8) {
echo "This script is not compatible with PHP 8 or higher yet\n";
if (PHP_MAJOR_VERSION >= 9) {
echo "This script is not compatible with PHP 9 or higher yet\n";
exit (1);
}

Expand Down Expand Up @@ -78,6 +78,7 @@ public function crawl(): void
$headers = ['Host: ' . $parsedFirstUrl['host'], 'X-Forwarded-Proto: ' . ($parsedUrl['scheme'] ?? 'https')];
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlHandle, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; FlownativeSitemapCrawler; +https://www.flownative.com)');
/** @noinspection CurlSslServerSpoofingInspection */
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
$status = curl_exec($curlHandle);
Expand Down Expand Up @@ -168,8 +169,8 @@ private function parseSitemap(string $sitemapUrl): void
$sitemapXml = new SimpleXMLElement($rawSitemapXml, LIBXML_NOBLANKS);
if ($sitemapXml->getName() === 'urlset') {
foreach ($sitemapXml->url as $urlXml) {
$url = reset($urlXml->loc);
if (!in_array($url, $this->urls)) {
$url = (string)$urlXml->loc;
if (!in_array($url, $this->urls, true)) {
$this->urls[] = $url;
}
}
Expand Down

0 comments on commit 7e2d31d

Please sign in to comment.