/**
  * @param string $_table
  */
 public function truncate($_table)
 {
     /* ## LOGGER ## */
     if (isset($this->logger)) {
         $this->logger->DEBUG('truncate: ' . $_table);
     }
     if (empty($_table)) {
         throw new UndefinedTabelException('null');
     }
     $table = $this->connection->escape($_table);
     $sql = 'TRUNCATE TABLE `' . $table . '`';
     $result = $this->connection->send($sql);
 }
 /**
  * @param string $_index
  */
 public function delete($_index)
 {
     /* ## LOGGER ## */
     if (isset($this->logger)) {
         $this->logger->DEBUG('delete');
     }
     if (empty($_index)) {
         throw new UndefinedRowException('null');
     }
     $table = $this->connection->escape($this->table);
     $primary = $this->connection->escape($this->primary);
     $index = $this->connection->escape($_index);
     $sql = 'DELETE FROM `' . $table . '` WHERE `' . $primary . '` = \'' . $index . '\';';
     $result = $this->connection->send($sql);
     if ($this->connection->getAffectedRows() <= 0) {
         throw new UndefinedRowException('undefined ' . $primary . '=' . $index);
     }
 }
Beispiel #3
0
 /**
  * Make an HTTP request
  *
  * @return string API results
  * @ignore
  */
 function http($url, $method, $postfields = NULL, $headers = array())
 {
     list($usec, $sec) = explode(" ", microtime());
     $begin = (double) $usec + (double) $sec;
     $this->http_info = array();
     $ci = curl_init();
     /* Curl settings */
     curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
     curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
     curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
     curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
     curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ci, CURLOPT_ENCODING, "");
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
     curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
     curl_setopt($ci, CURLOPT_HEADER, FALSE);
     curl_setopt($ci, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
     $config = HaloEnv::get('config');
     $debug = $config['app']['debug'];
     if (!isEmptyString($this->http_proxy)) {
         curl_setopt($ci, CURLOPT_PROXY, $this->http_proxy);
         if (Logger::isDebugEnabled()) {
             Logger::DEBUG('URL:[' . $url . '][PROXY:' . $this->http_proxy . ']', __FILE__, __LINE__, 'sina_api');
         }
     }
     if ($this->cookie) {
         if (isset($this->cookie['SUW'])) {
             $this->cookie['SUW'] = urldecode($this->cookie['SUW']);
             curl_setopt($ci, CURLOPT_REFERER, "http://weibo.cn");
         } else {
             curl_setopt($ci, CURLOPT_REFERER, "http://weibo.com");
         }
         $cookie = http_build_query($this->cookie, null, '; ');
         curl_setopt($ci, CURLOPT_COOKIE, $cookie);
     }
     switch ($method) {
         case 'POST':
             curl_setopt($ci, CURLOPT_POST, TRUE);
             if (!empty($postfields)) {
                 curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
                 $this->postdata = $postfields;
             }
             break;
         case 'DELETE':
             curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
             if (!empty($postfields)) {
                 $url = "{$url}?{$postfields}";
             }
     }
     if (isset($this->access_token) && $this->access_token) {
         $headers[] = "Authorization: OAuth2 " . $this->access_token;
     }
     $headers[] = "API-RemoteIP: " . $_SERVER['REMOTE_ADDR'];
     curl_setopt($ci, CURLOPT_URL, $url);
     curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
     $response = curl_exec($ci);
     $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
     $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
     $this->url = $url;
     if ($this->http_code != 200) {
         if (curl_errno($ci) == CURLE_OPERATION_TIMEOUTED) {
             Logger::ERROR("sina api timeout url is " . $url . ", sever ip is " . $_SERVER['REMOTE_ADDR'], "", "", "sina_api_timeout");
             //                $msg = urlencode("Fatal error sina api is timeout on ip ".$_SERVER['REMOTE_ADDR']);
             //                system('wget "http://223.202.17.147/insert_information.php?email=junqiang.liu@yolu-inc.com&info='.$msg.'&pass=fuck18324hfbdhfkgmxc" -O /dev/null -o /dev/null');
         }
         $e = new Exception();
         Logger::ERROR("&&&&&& Curl error is: " . print_r(curl_error($ci), true), "", "", "sina_api_error");
         Logger::ERROR(sprintf("====\ncode: %d\nurl:%s\nresponse:%s====\nstack:%s\ninfo:%s\n", $this->http_code, $url, $response, $e->getTraceAsString(), print_r(curl_getinfo($ci), true)), __FILE__, __LINE__, 'sina_api_error');
     }
     if ($this->debug) {
         echo "<hr/>=====post data======\r\n<pre>";
         // 			var_dump($postfields);
         echo '</pre><hr/>=====info=====' . "\r\n<pre>";
         // 			var_dump( curl_getinfo($ci) );
         echo '</pre><hr/>=====$response=====' . "\r\n";
         // 			var_dump( $response );
     }
     curl_close($ci);
     return $response;
 }
Beispiel #4
0
 public static function checkAccessType()
 {
     if (isset($_REQUEST['acc_type'])) {
         $_COOKIE['acc_type'] = $_REQUEST['acc_type'];
         header('Set-Cookie:acc_type=' . $_REQUEST['acc_type']);
     }
     Logger::DEBUG($_REQUEST['acc_type']);
     Logger::DEBUG($_COOKIE['acc_type']);
 }
Beispiel #5
0
  * @return bool
  */
 public function set($key, &$data, $expire = MemCacheBase::EXPIRE_DEFAULT)
 {
     if (self::$mc == null || empty($key)) {
         return false;
     }