Source for file Curl.php
Documentation is available at Curl.php
* DotBoost Technologies Inc.
* DotKernel Application Framework
* @copyright Copyright (c) 2009 DotBoost Technologies (http://www.dotboost.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @version $Id: Curl.php 152 2010-06-18 07:39:40Z teo $
* CURL with TOR and country proxy features
* @author DotKernel Team <team@dotkernel.com>
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3',
'Mozilla/5.0 (Windows; U; Windows NT 5.0; rv:1.7.3) Gecko/20040913 Firefox/0.10',
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
'Microsoft Internet Explorer/Version (Platform)',
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
'msnbot/1.0 (+http://search.msn.com/msnbot.htm)',
'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)'
* Used in case you want to specify userAgent
* Used in case you want to bypass tor proxy
* Use in case you want to use country proxy feature
* an array with available ports
public $ports = array(9000, 9001, 9002, 9003, 9004, 9005, 9006, 9007, 9008, 9009, 9010, 9011, 9012, 9013, 9014, 9015, 9016, 9017, 9018, 9019, 9020);
* General settings: sslVerifyPeer
* General settings: header
* General settings: returnTransfer
* General settings: followLocation
* General settings: timeOut
* Errors , view these in case no data is shown
* Info , stores curl_getinfo() response
* Post vars , leave empty if not needed
* Cookies , leave empty if not needed
* @param string $referer [optional]
private function setOptions($ch, $url, $referer = '')
//if no referer is provided, use the url as the referer
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $this->header);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeOut);
curl_setopt($ch, CURLOPT_REFERER, $referer);
//follow redirects , be carefull to se open_basedir to none and that php is not in safe mode
//get a random user agent
//if useTor is true connection will be done throu tor proxy
//for multy curl we build an array of already used ports to avoid using the same ports more then once
$this->usedPorts[] = $port;
curl_setopt ($ch, CURLOPT_PROXY, $this->torIp. ':'. $port);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
foreach($this->cookies as $k=> $v) $cc[] = "$k=$v";
curl_setopt ($ch, CURLOPT_COOKIE, implode('; ',$cc));
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $this->postVars);
* Fetch multiple urls at once
* @param array $referers [optional]
* @return array with requests results
public function getMulti($urls, $referers = array())
//reset every time to avoid stacking
$this->usedPorts = array();
foreach ($urls as $key => $val)
$referer = $referers[$key];
$obj[$key] = curl_init($url);
//set options for each url
curl_multi_add_handle($mh, $obj[$key]);
//execute all the urls at once
curl_multi_exec($mh,$running);
//retriev results from each request
foreach ($urls as $key => $val)
$htmls[$key] = curl_multi_getcontent($obj[$key]);
if (curl_errno($obj[$key]) != 0)
$this->errors[] = 'Connection problem (cURL ERROR: '. curl_errno($obj[$key]). ': '. curl_error($obj[$key]). ')';
curl_multi_remove_handle($mh, $obj[$key]);
//return the array wth all the results
* @param string $referer [optional]
public function getSingle($url, $referer = '')
//reset every time to avoid stacking
$this->usedPorts = array();
$content = curl_exec($obj);
$this->info = curl_getinfo($obj);
if (curl_errno($obj) != 0)
$this->errors[] = 'Connection problem (DOT CURL ERROR: '. curl_errno($obj). ': '. curl_error($obj). ')';
|