protected $curl_instance;
protected $request_timeout;
protected $debug;
protected $end_line;
protected $user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0';
protected function __construct($cookie_file, $request_timeout, $debug, $end_line)
{
parent::__construct($cookie_file);
$this->request_timeout = $request_timeout;
$this->debug = $debug;
$this->end_line = $end_line;
$this->initInstance();
}
protected function initInstance()
{
$this->curl_instance = curl_init();
if ($this->isValidateCookieFile()) {
curl_setopt($this->curl_instance, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($this->curl_instance, CURLOPT_COOKIEFILE, $this->cookie_file);
}
curl_setopt($this->curl_instance, CURLOPT_TIMEOUT, $this->request_timeout);
curl_setopt($this->curl_instance, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curl_instance, CURLOPT_HEADER, 1);
curl_setopt($this->curl_instance, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->curl_instance, CURLOPT_SSL_VERIFYHOST, 0);
curl_exec($this->curl_instance);
}
function setCookies($cookies)
{
$this->closeInstance();
$this->__setCookies($cookies);
$this->initInstance();
}
protected function getAllCookies($refresh = false)
{
$this->closeInstance();
$cookies = $this->__getAllCookies($refresh);
$this->initInstance();
return $cookies;
}
protected function clearAllCookies($refresh = false)
{
$this->closeInstance();
$this->__clearAllCookies();
if ($refresh) {
$this->initInstance();
}
}
protected function getCookie($name, $refresh = false)
{
$this->closeInstance();
$cookie = $this->__getCookie($name, $refresh);
$this->initInstance();
return $cookie;
}
protected function getRequestInstance()
{
return $this->curl_instance;
}
protected function closeInstance()
{
if (is_resource($this->curl_instance)) {
curl_close($this->curl_instance);
}
}
protected function resetInstance()
{
$this->closeInstance();
@unlink($this->cookie_file);
$this->initInstance();
}
protected function requestExec($option)
{
curl_setopt_array($this->getRequestInstance(), $option);
//if ($this->debug) {
// $result = curl_exec($this->getRequestInstance());
// Trace::write($result, $this->end_line, 'request output');
//} else {
return curl_exec($this->getRequestInstance());
//}
}
}
class QQVisitorRequest extends BaseRequest
{
protected $user;
protected $password;
protected function __construct($user, $password, $cookie_file, $request_timeout, $debug, $end_line)
{