/** * Set config option value * * @param string $name * @param mixed $value * @return mixed */ function setValue($name, $value) { $option = ConfigOptions::findByName($name); if (instance_of($option, 'ConfigOption')) { $option->setValue($value); $save = $option->save(); if ($save && !is_error($save)) { $cached_values = cache_get('config_values'); if (is_array($cached_values)) { $cached_values[$name] = $value; } else { $cached_values = array($name => $value); } // if cache_set('config_values', $cached_values); cache_remove(TABLE_PREFIX . 'config_options_name_' . $name); return $value; } else { return $save; } // if } else { return new InvalidParamError('name', $name, "System configuration option '{$name}' does not exist", true); } // if }
function enplacify_flickr_get_photo($photo_id) { if (!$GLOBALS['cfg']['flickr_apikey']) { return array('ok' => 0, 'error' => 'No Flickr API key'); } $cache_key = "enplacify_flickr_photo_{$photo_id}"; $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $url = "http://api.flickr.com/services/rest/?method=flickr.photos.getInfo"; $url .= "&photo_id={$photo_id}"; $url .= "&api_key={$GLOBALS['cfg']['flickr_apikey']}"; $url .= "&format=json&nojsoncallback=1"; $rsp = http_get($url); if (!$rsp['ok']) { return $rsp; } $json = json_decode($rsp['body'], "f**k off php"); if ($json['stat'] != 'ok') { return array('ok' => 0, 'error' => 'Flickr API error'); } $photo = $json['photo']; $rsp = array('ok' => 1, 'photo' => $json['photo']); cache_set($cache_key, $rsp); return $rsp; }
function flickr_photos_get_by_id($id) { $cache_key = "photo_{$id}"; $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $lookup = flickr_photos_lookup_photo($id); if (!$lookup) { return; } $user = users_get_by_id($lookup['user_id']); $cluster_id = $user['cluster_id']; # Temporary – this should never happen if (!$cluster_id) { return null; } $enc_id = AddSlashes($id); $sql = "SELECT * FROM FlickrPhotos WHERE id='{$enc_id}'"; $rsp = db_fetch_users($cluster_id, $sql); $row = db_single($rsp); if ($row) { cache_set($cache_key, $row, "cache_locally"); } return $row; }
function sheets_lookup_by_fingerprint($fingerprint, $user_id = 0) { $cache_key = "sheets_lookup_fingerprint_{$fingerprint}"; $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } # $enc_fingerprint = AddSlashes($fingerprint); $sql = "SELECT * FROM SheetsLookup WHERE fingerprint='{$enc_fingerprint}'"; if ($user_id) { $enc_id = AddSlashes($user_id); $sql .= " AND user_id='{$enc_id}'"; } $rsp = db_fetch($sql); $sheets = array(); foreach ($rsp['rows'] as $row) { $more = array('sheet_user_id' => $row['user_id']); if ($sheet = sheets_get_sheet($row['sheet_id'], $user_id, $more)) { $sheets[] = $sheet; } } cache_set($cache_key, $sheets); return $sheets; }
/** * Display preview method * * NOTE : parent_object & parent_action are used to determine */ function _display_preview($params = [], $template = "") { $replace = $params['replace']; $PARENT_OBJECT = $_REQUEST["parent_object"]; $PARENT_ACTION = $_REQUEST["parent_action"]; // If no custom replace given, try to make own if (empty($replace)) { foreach ((array) $_POST as $k => $v) { if (in_array($v, $this->skip_fields)) { continue; } if ($k != 'category_id') { $replace[$k] = $this->_format_text($v); } else { // Try to get category_id based on parent object $categories = cache_get($PARENT_OBJECT . "_categories"); $replace['category_id'] = $categories[$v]; } } } // Try to get template if (false !== strpos($_POST['preview_form_action'], "add_comment")) { $body = tpl()->parse("comments/preview", $replace); } else { $stpl_name = $PARENT_OBJECT . "/" . $PARENT_ACTION . "_preview"; $body = tpl()->_stpl_exists($stpl_name) ? tpl()->parse($stpl_name, $replace) : ""; } // Default body if (empty($body)) { $body = tpl()->parse(__CLASS__ . "/default", $replace); } // Process template $replace2 = ["template" => $body]; return common()->show_empty_page(tpl()->parse("preview/main", $replace2), ["title" => t("Preview")]); }
/** * Return all users assigned to a specific object * * @param ProjectObject $object * @return array */ function findAssigneesByObject($object) { $cache_id = 'object_assignments_' . $object->getId(); $cached_values = cache_get($cache_id); if (is_array($cached_values)) { if (count($cached_values) > 0) { return Users::findByIds($cached_values); } else { return null; } // if } // if $users_table = TABLE_PREFIX . 'users'; $assignments_table = TABLE_PREFIX . 'assignments'; $cached_values = array(); $rows = db_execute_all("SELECT {$users_table}.id FROM {$users_table}, {$assignments_table} WHERE {$assignments_table}.object_id = ? AND {$assignments_table}.user_id = {$users_table}.id", $object->getId()); if (is_foreachable($rows)) { foreach ($rows as $row) { $cached_values[] = (int) $row['id']; } // foreach } // if cache_set($cache_id, $cached_values); if (count($cached_values) > 0) { return Users::findByIds($cached_values); } else { return null; } // if }
function flickr_photos_metadata_load(&$photo) { $cache_key = "photos_meta_{$photo['id']}"; $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $meta = flickr_photos_metadata_path($photo); if (!file_exists($meta)) { return array('ok' => 0, 'error' => 'missing meta file'); } $fh = fopen($meta, "r"); $data = fread($fh, filesize($meta)); fclose($fh); $data = json_decode($data, "as hash"); # guh... just in case stuff has been double # json encoded; this was a by-product of moving # over to the http_multi stuff and not realizing # what I was doing (20111114/straup) if ($data && !is_array($data)) { $data = json_decode($data, "as hash"); } if (!$data) { return array('ok' => 0, 'error' => 'failed to decode'); } $rsp = array('ok' => 1, 'data' => $data); cache_set($cache_key, $rsp); return $rsp; }
/** * Return value of $name config option for a given project * * @param string $name * @param Project $project * @return mixed */ function getValue($name, $project) { $cache_id = 'project_config_options_' . $project->getId(); $cached_value = cache_get($cache_id); if (is_array($cached_value) && isset($cached_value[$name])) { return $cached_value[$name]; } // if $option = ConfigOptions::findByName($name, PROJECT_CONFIG_OPTION); if (instance_of($option, 'ConfigOption')) { $record = db_execute_one('SELECT value FROM ' . TABLE_PREFIX . 'project_config_options WHERE project_id = ? AND name = ?', $project->getId(), $name); if (is_array($record) && isset($record['value'])) { $value = trim($record['value']) != '' ? unserialize($record['value']) : null; } else { $value = $option->getValue(); } // if if (is_array($cached_value)) { $cached_value[$name] = $value; } else { $cached_value = array($name => $value); } // if cache_set($cache_id, $cached_value); return $value; } else { return new InvalidParamError('name', $name, "Project configuration option '{$name}' does not exist", true); } // if }
/** * Checks if a resource exists and returns it if so. * * @param string $filename The resource name * @param bool $return_url If true returns an URL, else returns true or false depending on if the resource exists * @param bool $as_local_path If true returns not URL, but a filepath in local filesystem. Needs $return_url=true. * @param bool $nocache If true skips all internal caches and peforms a search now * @return string Depending on $return_url returns: (the resource URL or false on error) OR (true or false) */ function resourceExists($filename, $return_url = false, $as_local_path = false, $nocache = false) { global $CONFIG; $cnc = substr(appendVersion('/'), 1); $key = (isSSL() ? "resource_ssl_{$filename}" : "resource_{$filename}") . "_{$cnc}" . ($as_local_path ? "_l" : ""); if (!$nocache && ($res = cache_get($key)) !== false) { return $return_url ? $res : $res != "0"; } $ext = pathinfo($filename, PATHINFO_EXTENSION); $reg = "/(^{$ext}\$|^{$ext}\\||\\|{$ext}\$)/i"; foreach ($CONFIG['resources'] as $conf) { if (strpos("|" . $conf['ext'] . "|", "|" . $ext . "|") === false) { continue; } if (!file_exists($conf['path'] . '/' . $filename)) { continue; } if ($as_local_path) { return $conf['path'] . '/' . $filename; } $nc = $conf['append_nc'] ? $cnc : ''; $res = can_nocache() ? $conf['url'] . $nc . $filename : $conf['url'] . $filename . "?_nc=" . substr($nc, 2, -1); if (!$nocache) { cache_set($key, $res); } return $return_url ? $res : true; } cache_set($key, "0"); return false; }
function google_get_mymaps_kml_feed($url) { $cache_key = "mymaps_kml_" . md5($url); $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $parts = utils_parse_url($url); if (!google_is_mymaps_hostname($parts['host'])) { return null; } if ($parts['path'] != '/maps/ms') { return null; } $query = array(); foreach (explode("&", $parts['query']) as $q) { list($key, $value) = explode("=", $q, 2); $query[$key] = $value; } if (!$query['msid']) { return null; } $query['output'] = 'kml'; $feed_url = "http://{$parts['host']}{$parts['path']}?" . http_build_query($query); # cache_set($cache_key, $feed_url, "cache locally"); return $feed_url; }
/** * Add custom PHPTemplate variable into the page template */ function ninesixtyrobots_preprocess_page(&$vars) { // Check if the theme is using Twitter. $use_twitter = theme_get_setting('use_twitter'); if (is_null($use_twitter)) { $use_twitter = 1; } // If the theme uses Twitter pull it in and display it in the slogan. if ($use_twitter) { if ($cache = cache_get('ninesixtyrobots_tweets')) { $data = $cache->data; } else { $query = theme_get_setting('twitter_search_term'); if (is_null($query)) { $query = 'lullabot'; } $query = drupal_urlencode($query); $response = drupal_http_request('http://search.twitter.com/search.json?q=' . $query); if ($response->code == 200) { $data = json_decode($response->data); // Set a 5 minute cache on retrieving tweets. // Note if this isn't updating on your site *run cron*. cache_set('ninesixtyrobots_tweets', $data, 'cache', 300); } } $tweet = $data->results[array_rand($data->results)]; // Create the actual variable finally. $vars['site_slogan'] = check_plain(html_entity_decode($tweet->text)); } }
function enplacify_chowhound_get_restaurant($restaurant_id) { $cache_key = "enplacify_chowhound_restaurant_{$restaurant_id}"; $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $url = "http://www.chow.com/restaurants/" . urlencode($restaurant_id); $headers = array(); $more = array('follow_redirects' => 1); $rsp = http_get($url, $headers, $more); if (!$rsp['ok']) { return $rsp; } $vcard_rsp = vcard_parse_html($rsp['body']); $graph_rsp = opengraph_parse_html($rsp['body']); if (!$vcard_rsp['ok'] && !$graph_rsp['ok']) { $rsp = array('ok' => 0, 'error' => 'Failed to parse restaurant'); } else { $restaurant = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']); $restaurant['id'] = $restaurant_id; $rsp = array('ok' => 1, 'restaurant' => $restaurant); } cache_set($cache_key, $rsp); return $rsp; }
/** * {@inheritdoc} */ public function get($key) { if ($cache = cache_get($key)) { return $cache->data; } return NULL; }
function enplacify_dopplr_get_place($place_type, $place_id) { $cache_key = "enplacify_dopplr_{$place_type}_{$place_id}"; $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $url = "http://dplr.it/" . urlencode($place_type) . "/" . urlencode($place_id); $headers = array(); $more = array('follow_redirects' => 1); $rsp = http_get($url, $headers, $more); if (!$rsp['ok']) { return $rsp; } # https://github.com/mncaudill/flickr-machinetag-geo/blob/master/src/parsers/dopplr.php if (preg_match('#pointLat:(-?\\d.*),#U', $rsp['body'], $m)) { $latitude = floatval($m[1]); } if (preg_match('#pointLng:(-?\\d.*),#U', $rsp['body'], $m)) { $longitude = floatval($m[1]); } if (!$latitude || !$longitude) { return array('ok' => 0, 'error' => 'failed to locate lat,lon data'); } if (preg_match('#<title>(.*)\\|#U', $rsp['body'], $m)) { $name = trim($m[1]); } $place = array('latitude' => $latitude, 'longitude' => $longitude, 'url' => $url, 'name' => $name); $rsp = array('ok' => 1, 'place' => $place); cache_set($cache_key, $rsp); return $rsp; }
function show_post_by_category_controller($id) { $category = cache_get('category_' . $id); if (!$category) { $Posts = many_to_many_model('posts', 'categories', ['t.status' => 'published', 'r.category_id' => $id]); $posts = []; foreach ($Posts as $Post) { $post = one_to_many_model('posts', 'medias', 'left outer', ['t1.id' => $Post['id']]); $posts[] = $post->fetch(); } $categories = all_model('categories'); cache_put('front.category', 'category_' . $id, compact('categories', 'posts')); return; } else { response('200 Ok'); echo $category; return; } if (!empty($posts)) { response('200 Ok'); view('front.category', compact('posts', 'categories')); } else { throw new RuntimeException('418'); } }
function enplacify_yelp_get_listing($listing_id) { $cache_key = "enplacify_yelp_listing_{$listing_id}"; $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $url = "http://www.yelp.com/biz/" . urlencode($listing_id); $headers = array(); $more = array('follow_redirects' => 1); $rsp = http_get($url, $headers, $more); if (!$rsp['ok']) { return $rsp; } $vcard_rsp = vcard_parse_html($rsp['body']); $graph_rsp = opengraph_parse_html($rsp['body']); if (!$vcard_rsp['ok'] && !$graph_rsp['ok']) { $rsp = array('ok' => 0, 'error' => 'Failed to parse listing'); } else { $listing = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']); $listing['id'] = $listing_id; $rsp = array('ok' => 1, 'listing' => $listing); } cache_set($cache_key, $rsp); return $rsp; }
/** * Returns an associative array of classes known to extend Node. * Pulls this array from cache if available - if not, generates * and caches it. * * Class names are keyed on their machine name. * * @access private * @static * @return array */ private static function init_registry() { $cache = cache_get(self::DOODAL_CACHE_ID); ## ## Attempt to get registry from cache if ($cache && !empty($cache->data)) { return $cache->data; } else { ## ## Load all classes registered for autoloading not in an ignored (i.e. system) module $results = db_query("SELECT name FROM {registry} WHERE type = 'class' AND module != '' AND module NOT IN (:modules) ORDER BY name", array(':modules' => self::get_ignored_modules()))->fetchAll(); ## ## Get subset of classes marked as "node" $registry = array(); foreach ($results as $result) { $reflectedClass = new ReflectionAnnotatedClass($result->name); if ($reflectedClass->hasAnnotation('MachineName')) { $registry[$reflectedClass->getAnnotation('MachineName')->value] = $result->name; } } ## ## Cache results and return cache_set(self::DOODAL_CACHE_ID, $registry, 'cache', CACHE_PERMANENT); return $registry; } }
/** * Constructor * * @param $users * Mandatory - An array of integers or single integer specifying the Drupal users to notify. * * @param $defaultMessage * String: The default message to send in the email, overridden with the message stored in the template_data record * * @param $defaultSubject * String: The default email subject, overridden with the message stored in the template_data record * * @param $queueID * Integer: The QueueID associated with the message you're sending out * * @param $type * String: The actual notification type using the MaestroNotificationTypes Constants */ function __construct($defaultMessage = '', $defaultSubject = '', $queueID = 0, $type = MaestroNotificationTypes::ASSIGNMENT) { $observers = array(); $this->_notificationType = $type; $this->_queueID = $queueID; $this->getNotificationUserIDs(); $this->setNotificationSubjectAndMessage($defaultMessage, $defaultSubject); //Now, lets determine if we've got our observers cached. If not, lets rebuild that observer list //This is how we subscribe to becoming a notification provider for Maestro. $observers = cache_get('maestro_notification_observers'); if ($observers === FALSE) { //build the observer cache //need to scan through each available class type and fetch its corresponding context menu. foreach (module_implements('maestro_notification_observer') as $module) { $function = $module . '_maestro_notification_observer'; if ($declaredObserver = $function()) { foreach ($declaredObserver as $observerToCache) { $observers[] = $observerToCache; $this->_observers[] = $observerToCache; } } } cache_set('maestro_notification_observers', $observers); } else { $this->_observers = $observers->data; } }
function flickr_get_georss_feed($url) { $cache_key = "flickr_georss_" . md5($url); $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $http_rsp = http_get($url); $html = mb_convert_encoding($http_rsp['body'], 'html-entities', 'utf-8'); libxml_use_internal_errors(true); $doc = new DOMDocument(); $ok = $doc->loadHTML($html); if (!$ok) { return null; } $feed_url = null; foreach ($doc->getElementsByTagName('link') as $link) { if ($link->getAttribute('rel') != 'alternate') { continue; } if ($link->getAttribute('type') != 'application/rss+xml') { continue; } $href = $link->getAttribute('href'); # For example (note how we ask for RSS 2.0 explicitly) : # http://api.flickr.com/services/feeds/geo/?id=35034348999@N01&lang=en-us if (preg_match("/\\/geo\\//", $href)) { $feed_url = $href . "&format=rss_200"; break; } } cache_set($cache_key, $feed_url, "cache locally"); return $feed_url; }
function enplacify_openstreetmap_get_place($place_type, $place_id) { $cache_key = "enplacify_openstreetmap_{$place_type}_{$place_id}"; $cache = cache_get($cache_key); if ($cache['ok']) { return $cache['data']; } $url = "www.openstreetmap.org/api/0.6/" . urlencode($place_type) . "/" . urlencode($place_id); $rsp = http_get($url); if (!$rsp['ok']) { return $rsp; } $xml = new DOMDocument(); $xml->preserveWhiteSpace = false; $ok = $xml->loadXML($rsp['body']); if (!$ok) { return array('ok' => 0, 'error' => 'XML parse error'); } $ima = $xml->documentElement->firstChild; $lat = $ima->getAttribute('lat'); $lon = $ima->getAttribute('lon'); $tags = array(); foreach ($ima->childNodes as $tag) { $key = $tag->getAttribute('k'); $value = $tag->getAttribute('v'); $tags[$key] = $value; } $tags['latitude'] = $lat; $tags['longitude'] = $lon; $rsp = array('ok' => 1); $rsp[$place_type] = $tags; cache_set($cache_key, $rsp); return $rsp; }
public function query($sql) { $cache_time = $this->cache_time; if ($cache_time > 0) { if (cache_exists($sql, $cache_time, CACHE_SELECT_PATH)) { $this->opt_reset(); //查询参数初始化 return cache_get($sql, CACHE_SELECT_PATH); } } if (!$this->exe($sql)) { return false; } $list = array(); if (!$this->lastquery) { return false; } while (($res = $this->fetch()) != false) { $list[] = $res; } if ($cache_time > 0) { cache_set($sql, $list, $cache_time, CACHE_SELECT_PATH); } return $list ? $list : false; }
/** * Attempt to get a value from cache given the id specified by $cid * if no value is found in cache, then value specified by $data is * returned. if no $data is specified it will return NULL * * @param string $cid * @param mixed $data */ public function get($cid, $data = NULL) { $cache = cache_get($cid, 'cache_mint'); if ($cache !== FALSE) { $data = $cache->data; } return $data; }
/** * Checks the Module::getNamespaces() method. */ public function testModuleNamespaces() { $expected_values = array('Drupal\\plug' => drupal_get_path('module', 'plug') . '/src', 'Drupal\\field' => 'modules/field/src', 'Drupal\\field_sql_storage' => 'modules/field/modules/field_sql_storage/src', 'Drupal\\filter' => 'modules/filter/src', 'Drupal\\node' => 'modules/node/src', 'Drupal\\user' => 'modules/user/src', 'Drupal\\standard' => 'profiles/standard/src', 'Drupal\\system' => 'modules/system/src'); $namespaces = Module::getNamespaces(); $this->assertEqual($expected_values, array_intersect_assoc($namespaces->getArrayCopy(), $expected_values)); $cached_data = cache_get('module_namespaces'); $this->assertEqual($expected_values, array_intersect_assoc($cached_data->data, $expected_values)); }
function friendlink_find_cache($life = 300) { $friendlinklist = cache_get('friendlinklist'); if ($friendlinklist === NULL) { $friendlinklist = friendlink_find(); cache_set('friendlinklist', $friendlinklist, $life); } return $friendlinklist; }
function cron_run($force = 0) { global $conf, $time, $forumlist, $runtime; $cron_1_last_date = runtime_get('cron_1_last_date'); $cron_2_last_date = runtime_get('cron_2_last_date'); $t = $time - $cron_1_last_date; if ($t > 300 || $force) { $lock = cache_get('cron_lock_1'); if ($lock === NULL) { cache_set('cron_lock_1', 1, 10); // 设置 10 秒超时 // 清理在线 online_gc(); runtime_set('cron_1_last_date', $time); cache_delete('cron_lock_1'); } } $t = $time - $cron_2_last_date; if ($t > 86400 || $force) { $lock = cache_get('cron_lock_2'); // 高并发下, mysql 机制实现的锁锁不住,但是没关系 if ($lock === NULL) { cache_set('cron_lock_2', 1, 10); // 设置 10 秒超时 // 每日统计清 0 runtime_set('todayposts', 0); runtime_set('todaythreads', 0); runtime_set('todayusers', 0); foreach ($forumlist as $fid => $forum) { forum__update($fid, array('todayposts' => 0, 'todaythreads' => 0)); } forum_list_cache_delete(); // 清理最新发帖,只保留 100 条。 thread_new_gc(); thread_lastpid_gc(); // 清理在线 online_gc(); // 清理临时附件 attach_gc(); // 清空每日 IP 限制 ipaccess_truncate(); // 清理游客喜欢限制 guest_agree_truncate(); list($y, $n, $d) = explode(' ', date('Y n j', $time)); // 0 点 $today = mktime(0, 0, 0, $n, $d, $y); // -8 hours runtime_set('cron_2_last_date', $today, TRUE); // 加到1天后 // 每日生成最新的 sitemap thread_new_sitemap(); // 往前推8个小时,尽量保证在前一天 table_day_cron($time - 8 * 3600); cache_delete('cron_lock_2'); } } }
/** * Reads a saved HTTP response from a cachefile. * If caching is globally disabled ($config['IMDBage'] <= 0), file is not loaded. * * @param string $url URL of the cached response * @return mixed HTTP Response, false on errors */ function getHTTPcache($url) { global $config; if (@$config['cache_pruning']) { $cache_file = cache_get_filename($url, CACHE_HTML); cache_prune_folder(dirname($cache_file) . '/', $config['IMDBage']); } return cache_get($url, CACHE_HTML, $config['IMDBage'], true); }
function group_list_cache() { $grouplist = cache_get('grouplist'); if ($grouplist === NULL) { $grouplist = group_find(); cache_set('grouplist', $grouplist); } return $grouplist; }
/** * A copy of cache_get() that respects expiration. * * @see http://drupal.org/node/534092 */ public static function get($cid, $bin = 'cache') { if ($cache = cache_get($cid, $bin)) { if (!static::isCacheUnexpired($cache)) { return FALSE; } } return $cache; }
/** * Downloads remote contents into a string. * * @param string $url URL to download * @param array|string $postdata Data to POST, associative array or string from <http_build_query> * @param array $request_header Headers to send along with the request (one entry per header) * @param int $cacheTTLsec If set: time to life in cache * @param int $request_timeout Timeout in seconds * @param array $response_header <b>OUT</b> Will contain the reponse headers * @param string $cookie_file Name of the cookie file to use * @return string The downloaded data */ function downloadData($url, $postdata = false, $request_header = array(), $cacheTTLsec = false, $request_timeout = 120, &$response_header = false, $cookie_file = false) { if (starts_with($url, '//')) { $url = urlScheme() . ':' . $url; } if ($cacheTTLsec) { $hash = md5($url . "|" . ($postdata ? serialize($postdata) : "")); $ret = cache_get("CURL_{$hash}"); if ($ret !== false) { return $ret; } } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_TIMEOUT, abs($request_timeout)); if ($postdata) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); if (is_string($postdata)) { if (!is_array($request_header)) { $request_header = array(); } $request_header[] = "Content-Length: " . strlen($postdata); } } curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if ($cookie_file) { curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); } if (is_array($request_header) && count($request_header) > 0) { curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header); } $result = curl_exec($ch); $info = curl_getinfo($ch); if ($result === false) { log_error('Curl error: ' . curl_error($ch), "url = ", $url, "curl_info = ", $info); curl_close($ch); return $result; } //log_info($info); curl_close($ch); if ($response_header !== false) { $response_header = substr($result, 0, $info['header_size']); } $result = substr($result, $info['header_size']); if ($cacheTTLsec) { cache_set("CURL_{$hash}", $result, $cacheTTLsec); } return $result; }
function thread_top_find_cache() { global $conf; $threadlist = cache_get('thread_top_list'); if ($threadlist === NULL) { $threadlist = thread_top_find(); cache_set('thread_top_list', $threadlist); } return $threadlist; }