Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/mageworx/module-xmlsitemap/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/mageworx/module-xmlsitemap/Model/LinkChecker.php
<?php
/**
 * Copyright © MageWorx. All rights reserved.
 * See LICENSE.txt for license details.
 */

namespace MageWorx\XmlSitemap\Model;

use Exception;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\HTTP\ClientFactory;
use Psr\Log\LoggerInterface;

class LinkChecker
{
    /**
     * @var ClientFactory
     */
    protected $client;

    /**
     * LinkChecker constructor.
     *
     * @param ClientFactory $clientFactory
     */
    public function __construct(
        ClientFactory $clientFactory
    ) {
        $this->client = $clientFactory;
    }

    /**
     * Retrieves the array key of first URL with response code = 200 from set.
     *
     * @param array $urls
     * @param int $storeId
     * @return string|false
     */
    public function checkUrls($urls, $storeId)
    {
        foreach ($urls as $urlType => $url) {

            $logger = ObjectManager::getInstance()->get(LoggerInterface::class);
            $logger->info($url);

            try {
                $curl = $this->client->create();
                $curl->setOptions(
                    [
                        CURLOPT_NOBODY         => true,
                        CURLOPT_CONNECTTIMEOUT => 5
                    ]
                );
                $curl->get($url);
                $status = $curl->getStatus();
            } catch (Exception $exception) {
                return false;
            }

            if ($status == 200) {
                return $urlType;
            }
        }

        return false;
    }
}

Spamworldpro Mini