Esempio n. 1
0
 /**
  *
  */
 public function testMultiRequest()
 {
     $multi = new dHttp\Client();
     $response_array = $multi->multi([new dHttp\Client('http://php.net', [CURLOPT_FOLLOWLOCATION => true]), new dHttp\Client('http://www.python.org/', [CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1', CURLOPT_TIMEOUT => 10, CURLOPT_FOLLOWLOCATION => true])]);
     /* @var $item \dHttp\Response */
     foreach ($response_array as $item) {
         self::assertInstanceOf('dHttp\\Response', $item);
         self::assertEquals($item->getCode(), 200);
     }
 }
Esempio n. 2
0
 /**
  * Return http client
  *
  * @param string $url
  * @param array $options
  * @return dHttp\Client
  */
 protected function getClient($url, $options = [])
 {
     if ($this->httpClient == null) {
         $this->httpClient = new dHttp\Client();
     }
     $defaultOptions = [CURLOPT_REFERER => $this->baseUrl, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 20, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.102 Safari/537.36'];
     return $this->httpClient->reset()->addOptions($defaultOptions + $options)->setUrl($url);
 }
Esempio n. 3
0
            foreach (pq('noindex') as $noindex) {
                if (stripos(pq($noindex)->text(), $target))$local_result['nix'] = 'ni';
            }
        }
        ($local_result['rd'] != 'rd'&&$local_result['nix'] != 'ni'&&$local_result['nfl'] != 'nf')?$local_result['clear'] = true:'';
        $hook?$local_result['live'] = true:$local_result['live'] = false;
        unset($data);
        phpQuery::unloadDocuments();
    }
    else {
        $local_result['live'] = 'handed';
    }
    return $local_result;
};

$multi = new dHttp\Client();
$used_links = array();
foreach ($params as $url) {
    $url = trim($url);
    if(!in_array($url,$used_links)) {
        $resp_once[] = new dHttp\Client($url, array(
            CURLOPT_SSL_VERIFYPEER => FALSE,
            CURLOPT_HEADER => TRUE,
            CURLOPT_TIMEOUT_MS => 120000,
            CURLOPT_FOLLOWLOCATION => TRUE,
            CURLOPT_IPRESOLVE => 'CURL_IPRESOLVE_V4',
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'
        ));
        $used_links[] = $url;
    }
Esempio n. 4
0
// Get response body
$resp->getBody();
// Get request errors
$resp->getErrors();
/*
 * Simple post request
 */
$resp = $http->post(['field1' => 'value1', 'field2' => 'value2']);
$resp->getRaw();
// Return response headers
$resp->getHeaders();
// Return a specific (text/html; charset=utf-8)
$resp->getHeader('Content-Type');
/**
 * Another way of setting.
 * Output response
 */
$http = new dHttp\Client();
$http->addOptions([CURLOPT_RETURNTRANSFER => false])->setUserAgent('Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1')->setCookie('/tmp/cookies.txt')->setUrl('http://website.com')->get();
/**
 * Use multi curl
 */
$multi = new dHttp\Client();
$response_array = $multi->multi([new dHttp\Client('http://website1.com'), new dHttp\Client('http://website2.com', [CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1', CURLOPT_TIMEOUT => 5])]);
foreach ($response_array as $item) {
    $resp->getCode();
}
/**
 * Get cURL version
 */
\dHttp\Client::v();
Esempio n. 5
0
        $xmlString = file_get_contents('http://www.billboard.com/rss/charts/hot-100');
        $cache->set('top', $xmlString, 0, 8600);
    }
    $xml = new SimpleXMLElement($xmlString);
    $results = $xml->channel[0]->item;
    $app->render('layout.php', ['page' => 'main', 'results' => $results]);
});
// Search route
$app->get('/:query.html', function ($query) use($app) {
    $query = urlclean($query);
    // Save request
    $client = new \Sokil\Mongo\Client(MONGO_DSN);
    $collection = $client->getDatabase(MONGO_DBNAME)->getCollection(MONGO_COLLECTION);
    if (!$collection->find(['request' => $query])->count()) {
        $collection->insert(['request' => $query, 'created' => new MongoDate(), 'views' => 1]);
    } else {
        $collection->getMongoCollection()->update(['request' => $query], ['$inc' => ['views' => 1]]);
    }
    // Search from Vk or memcache
    $cache = new memcache();
    $cache->connect('localhost');
    // Поиск в ВК и отправка пользователю
    if (($results = $cache->get($query)) === false) {
        // Search from Vk or memcache
        $http = new dHttp\Client('https://api.vk.com/method/audio.search.json?access_token=096fb2d19fc28da6694e9db15f47ff9561c36628f5485fbcd642f7edc6185ea413ab2f2fa4a5c1789cb79&q=' . urlencode($query));
        $results = json_decode($http->get()->getBody(), true);
        $cache->set($query, json_decode($http->get()->getBody(), true), 0, 72000);
    }
    $app->render('layout.php', ['page' => 'search', 'results' => $results, 'query' => $query]);
})->conditions(['query' => '.+']);
$app->run();