Просмотр поста

.
Koenig
(\/)____o_O____(\/)

_endrju_, хз, как то так

class Resource
{
    private $data;
    
    private $url;
    
    private $ch;
    
    public function __construct($url, $data) {
        $this->url = $url;
        $this->data = $data;
        $this->createResourse();
    }
    
    public function createResourse() {
        $ch = curl_init($this->url);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_REFERER, $this->url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 6.0.1; D5803 Build/23.5.A.1.291) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.83 Mobile Safari/537.36');
        curl_setopt($ch, CURLOPT_ENCODING, 'utf-8');
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 200);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->data);
        curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/' . md5($this->url) . '_cookie.txt');
        curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/' . md5($this->url) . '_cookie.txt');
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        if (preg_match('/https:/', $this->url)) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        }
        
        $this->ch = $ch;
    }
    
    public function execute() {
        $data = curl_exec($this->ch);
        curl_close($this->ch);
        return $data;
    }
}

class Crawler
{
    private $resources = [];
    
    public function __construct(array $urls, array $posts) {
        $res = [];
        foreach (range(0, count($urls) - 1) as $key) {
            $res[] = new Resource($urls[$key], $posts[$key]);
        }
        $this->resources = $res;
    }
    
    public function run() {
        return array_map(
            function ($i) {
                sleep(0.35);
                return $i->execute();
            }, $this->resources
        );
    }
}

$urls = ['http://johncms.com', 'https://seclub.org'];
$posts = ['', ''];

$obj = new Crawler($urls, $posts);

echo '<pre>' . print_r(array_map('htmlspecialchars', $obj->run()), 1) . '</pre>';