Ejemplo n.º 1
0
 /**
  */
 function connect($params = [])
 {
     if (!$this->_connection) {
         $override = ['REDIS_HOST' => $this->_get_conf('REDIS_QUEUE_HOST'), 'REDIS_PORT' => $this->_get_conf('REDIS_QUEUE_PORT'), 'REDIS_PREFIX' => $this->_get_conf('REDIS_QUEUE_PREFIX')];
         $this->_connection = redis($params);
         $this->_connection->connect($override);
     }
     return $this->_connection;
 }
Ejemplo n.º 2
0
function log_action($user, $action) {
	if (!is_array($user) && strlen(number($user)) < 5)
		if ($u = user($user)) $user = $u;
	if (is_array($user)) $user = $user['phone'];
	redis()->lpush('actions', json_encode(array(
		'phone' => $user,
		'action' => $action,
		'time' => time(),
	)));
}
Ejemplo n.º 3
0
 public function gc($max)
 {
     $keys = redis()->keys('sessionsphp.*');
     foreach ($keys as $key) {
         $expires = redis()->hget($key, 'expires');
         if ($expires < time()) {
             redis()->del($key);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  */
 function connect($params = [])
 {
     if (!$this->_is_connection) {
         $override = ['REDIS_HOST' => $this->_get_conf('REDIS_PUBSUB_HOST'), 'REDIS_PORT' => $this->_get_conf('REDIS_PUBSUB_PORT'), 'REDIS_PREFIX' => $this->_get_conf('REDIS_PUBSUB_PREFIX')];
         $this->_connection_pub = clone redis($params);
         $this->_connection_pub->connect($override);
         $this->_connection_sub = clone redis($params);
         $this->_connection_sub->connect($override);
     }
     return $this->_is_connection;
 }
Ejemplo n.º 5
0
 public static function makeFrom($to, $from = null)
 {
     $defaultLng = Config::get('application.language', DEFAULT_LANGUAGE);
     $from = is_null($from) ? $defaultLng : $from;
     $keys = redis()->keys('lang.' . $from . '.*');
     if (count($rows)) {
         foreach ($rows as $row) {
             $save = redis()->get($row);
             list($dummy, $from, $id) = explode('.', $row, 3);
             self::getDb()->create(['key' => $id, 'language' => $to, 'translation' => $save])->save();
         }
     }
 }
Ejemplo n.º 6
0
 public function check()
 {
     /* CLI case */
     defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production');
     if ('production' == APPLICATION_ENV) {
         $ip = $_SERVER['REMOTE_ADDR'];
         $this->isBanned($ip);
         $key = 'ip.' . str_replace('.', '', $ip) . '.' . date('dmYHi') . '.flood';
         $val = redis()->incr($key);
         redis()->expire($key, 60);
         if ($val > Config::get('application.flood.maxPageByMinute', 30)) {
             $this->checkedBanned($ip);
             Api::forbidden();
         }
     }
 }
Ejemplo n.º 7
0
 public function exec($object = false, $count = false, $first = false)
 {
     if (!$object) {
         $hash = self::$instance->getHash($object, $count, $first);
         $ageDb = self::$instance->getAge();
         $key = 'dbredis.exec.' . $hash . '.' . $ageDb;
         $cache = redis()->get($key);
         if ($cache) {
             self::$instance->reset();
             return unserialize($cache);
         }
         $collection = call_user_func_array([static::$instance, 'exec'], func_get_args());
         redis()->set($key, serialize($collection));
         return $collection;
     } else {
         return call_user_func_array([static::$instance, 'exec'], func_get_args());
     }
 }
Ejemplo n.º 8
0
 public function test_redis()
 {
     $redis = redis();
     $this->assertInternalType('object', $redis);
     $this->assertSame($redis, _class('wrapper_redis'));
     $redis->connect();
     $this->assertTrue($redis->is_ready());
     $key = 'mytestkey';
     $val = 'mytestval';
     if ($redis->get($key)) {
         $this->assertEquals($redis->del($key), 1);
     }
     $this->assertEmpty($redis->get($key));
     $this->assertTrue($redis->set($key, $val));
     $this->assertEquals($redis->get($key), $val);
     $this->assertEquals($redis->del($key), 1);
     $this->assertEmpty($redis->get($key));
 }
Ejemplo n.º 9
0
 /**
  * Gets the actual result when available.
  * If timeout is reached before actual result is redeemed, a TimeoutException will be thrown.
  * If the actual result is an Exception, that Exception will be thrown.
  *
  * @param $timeout
  * @return mixed
  * @throws TimeoutException
  * @throws
  */
 public function get($timeout)
 {
     $blpop = redis()->blpop(self::RESULT . $this->asyncId, $timeout);
     if (isset($blpop[1])) {
         $this->result = crypto_unserialize($blpop[1]);
     } else {
         throw new TimeoutException();
     }
     redis()->del(FUTURE_LOCK . $this->asyncId);
     // remove lock
     if ($this->result instanceof Exception) {
         throw $this->result;
     }
     return $this->result;
 }
Ejemplo n.º 10
0
 /**
  */
 function _init()
 {
     $override = ['REDIS_HOST' => $this->_get_conf('REDIS_CACHE_HOST'), 'REDIS_PORT' => $this->_get_conf('REDIS_CACHE_PORT'), 'REDIS_PREFIX' => $this->_get_conf('REDIS_CACHE_PREFIX')];
     $this->_connection = redis();
     $this->_connection->connect($override);
 }
Ejemplo n.º 11
0
 public function import($file)
 {
     $content = redis()->get($file);
     if (!$content) {
         $content = 'return null;';
     }
     return eval($content);
 }
Ejemplo n.º 12
0
 public function ponterestSearch($rec)
 {
     $cached = redis()->get('pins.s.' . sha1($rec));
     if (!$cached) {
         $cached = file_get_contents("https://fr.pinterest.com/search/pins/?q=" . urlencode($rec));
         // $cached = dwn("https://fr.pinterest.com/search/pins/?q=" . urlencode($rec) . "&term_meta[]=" . urlencode($rec) . "|typed");
         redis()->set('pins.s.' . sha1($rec), $cached);
     }
     $data = Utils::cut('P.main.start(', '});', $cached) . '}';
     $data = json_decode($data, true);
     $resourceDataCache = isAke($data, 'resourceDataCache', []);
     $data = isAke(current($resourceDataCache), 'data', []);
     $results = isAke($data, 'results', []);
     dd($results);
 }
Ejemplo n.º 13
0
 public function searchWd($q)
 {
     /*https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q1631&format=json*/
     $keyCache = 'wm.search.' . sha1($q);
     $json = redis()->get($keyCache);
     if (!$json) {
         $json = file_get_contents('https://www.wikidata.org/w/api.php?action=wbsearchentities&search=' . urlencode($q) . '&language=fr&limit=20&format=json');
         redis()->set($keyCache, $json);
         redis()->expire($keyCache, strtotime('+6 month') - time());
     }
     $tab = json_decode($json, true);
     dd($tab);
 }
Ejemplo n.º 14
0
<?

restrict();
top();
?>


<h2>Users</h2>
<?
$users = redis()->hgetall('users');

function sort_users($a, $b) { return $a['name'] > $b['name']; }

usort(array_values($users), 'sort_users');

table();
foreach ($users as $user) {
	$user = json_decode($user, true);
	row(
		format_user($user),
		o($user, 'phone'),
		_href('/users/' . o($user, 'phone') . '/edit', '(edit)'),
		_href('javascript:if(confirm("Are you sure you want to delete ' . o($user, 'name') . '?")) window.location="/users/' . o($user, 'phone') . '/delete"', '(delete)')
	);
}
endtable();

href('/users/create', 'Create New User');

bottom();
Ejemplo n.º 15
0
 public function index()
 {
     $_GET = array_merge($_GET, $_POST);
     $k = I("request.keyword");
     $first = I("request.first");
     // 默认搜索第一个热搜词
     if (!$k && $first) {
         $k = $first;
     }
     if ($k) {
         $redis = redis();
         $redis->select(1);
         // var_dump($redis->keys());die;
         $redis->zIncrBy('hot_search', '1', $k);
         // 搜索词+1,不存在则创建
         // var_dump($redis->zRange('hot_search' , 0 ,-1));die;
         // var_dump($redis->zRevRange('search', 0, 5, true));//取出排名前5的搜索词
         // $redis->lPushx('hotsearch' , $k);
         // $redis->lpush( 'hotsearch' , $k);
         $history['uid'] = 0;
         $history['keyword'] = $k;
         $history['add_time'] = time();
         M('Search_history')->add($history);
     }
     // 搜索
     $client = elasticsearch();
     $query = array();
     $cate_id = I('request.cate_id');
     if ($cate_id) {
         $query['must'][]['term']['cate_id'] = $cate_id;
         $this->assign("cate_id", $cate_id);
     }
     $format = I('request.format');
     if ($format) {
         $query['must'][]['term']['format'] = I('post.format');
         $this->assign("format", $format);
     }
     $preorder = I('request.preorder');
     if ($preorder) {
         $query['must'][]['term']['preorder'] = $preorder;
         $this->assign("preorder", $preorder);
     }
     $released_from = I('request.released_from');
     $released_to = I('request.released_to');
     if ($released_from) {
         $query['must'][]['range']['released'] = array('from' => $released_from, 'to' => $released_to);
         $this->assign("released_from", $released_from);
         $this->assign("released_to", $released_to);
     }
     $price_greater_than = I('request.price_greater_than');
     $price_less_than = I('request.price_less_than');
     if ($price_greater_than && $price_less_than) {
         $query['must'][]['range']['price'] = array('from' => $price_greater_than, 'to' => $price_less_than);
         $this->assign("price_greater_than", $price_greater_than);
         $this->assign("price_less_than", $price_less_than);
     }
     $availability = I('request.availability');
     if ($format) {
         $query['must'][]['term']['availability'] = $availability;
         $this->assign("availability", $availability);
     }
     if ($k) {
         $querystring['query_string']['default_field'] = '_all';
         $querystring['query_string']['query'] = $k;
         $query['must'][] = $querystring;
     }
     // sort
     if (I('get.sort')) {
         $sort = I('get.sort');
     } else {
         $sort = 'default';
     }
     if ('default' == $sort) {
         $param['sort'] = array(array('sales' => array('order' => 'desc')), array('comment' => array('order' => 'desc')), array('price' => array('order' => 'desc')));
     } else {
         $param['sort'] = array(array($sort => array('order' => 'desc')));
     }
     $p = I('get.p');
     $size = '20';
     if ($p) {
         $form = ($p - 1) * $size;
     } else {
         $form = 0;
     }
     $param['from'] = $form;
     $param['size'] = $size;
     $param['query']['bool'] = $query;
     //var_dump( $param );
     $json = json_encode($param, true);
     $params['index'] = 'ec_' . C('DB_NAME');
     $params['type'] = 'ec_goods';
     $params['body'] = $json;
     //var_dump( $json );
     $results = $client->search($params);
     $page = $this->page($results['hits']['total'], $size);
     $page_simple = $this->page_simple($results['hits']['total'], $size);
     // 推荐商品
     $lists = M('Goods')->field('id,name,price,img_url')->where('isrec=1')->limit(3)->order('id desc')->select();
     $this->assign("recGoods", $lists);
     $this->assign("keyword", $k);
     $this->assign("sort", I('get.sort'));
     $this->assign("lists", $results['hits']['hits']);
     $this->assign("Page", $page->show());
     $this->assign("page_simple", $page_simple->show());
     $this->display();
 }
Ejemplo n.º 16
0
 public function getEdges($key)
 {
     $collection = [];
     $keys = redis()->keys('g:*:i:' . $this->ns);
     foreach ($keys as $k) {
         if (fnmatch('*:d:*', $k) || fnmatch('*:data:*', $k)) {
             continue;
         }
         $m = redis()->smembers($k);
         if (in_array($key, $m) && !in_array(str_replace(['g:', ':i:' . $this->ns], '', $k), $collection)) {
             $collection[] = str_replace(['g:', ':i:' . $this->ns], '', $k);
         }
     }
     $keys = redis()->keys('g:*:o:' . $this->ns);
     foreach ($keys as $k) {
         if (fnmatch('*:d:*', $k) || fnmatch('*:data:*', $k)) {
             continue;
         }
         $m = redis()->smembers($k);
         if (in_array($key, $m) && !in_array(str_replace(['g:', ':o:' . $this->ns], '', $k), $collection)) {
             $collection[] = str_replace(['g:', ':o:' . $this->ns], '', $k);
         }
     }
     return $collection;
 }
Ejemplo n.º 17
0
 public function validate($offerout_id, $reselleremployee_id)
 {
     $error = [];
     try {
         $offerout = Model::Offerout()->findOrFail((int) $offerout_id);
     } catch (Exception $e) {
         $error['error'] = 'no_offer_out';
         return $error;
     }
     try {
         $reselleremployee = Model::Reselleremployee()->findOrFail((int) $reselleremployee_id);
     } catch (Exception $e) {
         $error['error'] = 'employee_unknown';
         return $error;
     }
     try {
         $offerin = Model::Offerin()->findOrFail((int) $offerout->offerin_id);
     } catch (Exception $e) {
         $error['error'] = 'no_offer_out';
         return $error;
     }
     if ($reselleremployee->reseller_id != $offerout->reseller_id) {
         $error['error'] = 'employee_unknown';
         return $error;
     }
     $offerout->reselleremployee_id = (int) $reselleremployee_id;
     if (isset($offerout->start) && isset($offerout->end)) {
         $isLock = redis()->get('lock.offerout.' . $reselleremployee_id);
         if (!empty($isLock)) {
             for ($i = 0; $i < 10; $i++) {
                 $isLock = redis()->get('lock.offerout.' . $reselleremployee_id);
                 if (empty($isLock)) {
                     break;
                 }
                 sleep(0.2);
             }
             if (!empty($isLock)) {
                 $error['error'] = 'is_lock';
                 return $error;
             }
         } else {
             redis()->set('lock.offerout.' . $reselleremployee_id, true);
             redis()->expire('lock.offerout.' . $reselleremployee_id, 10);
         }
         $check = $this->employeeIsYetAvailable((int) $offerout_id, (int) $reselleremployee_id);
         if (!$check) {
             $error['error'] = 'already_taken';
             redis()->del('lock.offerout.' . $reselleremployee_id);
             return $error;
         } else {
             lib('agenda')->addAppointment((int) $offerout->start, (int) $offerout->end, (int) $reselleremployee->reseller_id, (int) $reselleremployee_id, (int) $offerout_id);
             redis()->del('lock.offerout.' . $reselleremployee_id);
         }
     }
     if (isset($offerin->account_id)) {
         $offerout->account_id = (int) $offerin->account_id;
         $offerout = $offerout->save();
     }
     if (isset($offerin->company_id)) {
         $offerout->company_id = (int) $offerin->account_id;
         $offerout = $offerout->save();
     }
     return $this->status('TO_PAY', $offerin, $offerout);
 }
Ejemplo n.º 18
0
 public function mic($zip = 21000, $city = 'dijon')
 {
     $db = rdb('michelin', 'resto');
     $page = 1;
     $url = "http://restaurant.michelin.fr/ajaxSearchRestaurant/france/{$zip}-{$city}/page-##page##";
     $urlTo = str_replace('##page##', $page, $url);
     $etabs = redis()->get("resto.mic.{$zip}.{$city}");
     if (!$etabs) {
         $restos = [];
         $json = dwn($urlTo);
         $etabs = json_decode($json, true);
         $asyncPoiList = isAke($etabs, 'asyncPoiList', []);
         $stats = isAke($asyncPoiList, 'stats', []);
         $nbresults = (int) isAke($stats, 'tag_vm_nbresults_total', 0);
         $Oj = isAke($asyncPoiList, 'Oj', []);
         $restos = array_merge($restos, $Oj);
         $nbPages = ceil($nbresults / 18);
         for ($i = 2; $i <= $nbPages; $i++) {
             $urlTo = str_replace('##page##', $i, $url);
             $json = dwn($urlTo);
             $etabs = json_decode($json, true);
             $asyncPoiList = isAke($etabs, 'asyncPoiList', []);
             $Oj = isAke($asyncPoiList, 'Oj', []);
             $restos = array_merge($restos, $Oj);
         }
         redis()->set("resto.mic.{$zip}.{$city}", serialize($restos));
     } else {
         $etabs = unserialize($etabs);
         foreach ($etabs as $etab) {
             $id = isAke($etab, 'id', false);
             if (false !== $id) {
                 $infoUrl = "http://vmrest.viamichelin.com/apir/2/FindPOIByCriteria.json/RESTAURANT/fra?&filter=poi_id%20in%20%5B{$id}%5D&obfuscation=true&ie=UTF-8&charset=UTF-8&callback=JSE.cr.pv[0].cv&authKey=JSBS20111110142911566673070414&lg=fra&nocache=1433580926785";
                 $data = redis()->get("restos.mic.{$id}");
                 if (!$data) {
                     $html = dwn($infoUrl);
                     $json = Utils::cut('cv(', '}]}]})', $html) . '}]}]}';
                     $data = json_decode($json, true);
                     $resto = isAke($data, 'Oj', []);
                     if (!empty($resto)) {
                         $resto = current($resto);
                         $datasheets = isAke($resto, 'datasheets', []);
                         if (!empty($datasheets)) {
                             $numFound = false;
                             foreach ($datasheets as $ds) {
                                 $ds['poi_id'] = $id;
                                 $dts_id = isAke($ds, 'dts_id', 'a');
                                 if (is_numeric($dts_id)) {
                                     $numFound = true;
                                 }
                                 $resto = $ds;
                             }
                             redis()->set("restos.mic.{$id}", serialize($resto));
                         }
                     }
                 } else {
                     $data = unserialize($data);
                     $data['phone'] = (string) $data['phone'];
                     $data['local_phone'] = (string) $data['local_phone'];
                     $row = $db->firstOrCreate(['poi_id' => $data['poi_id']]);
                     foreach ($data as $k => $v) {
                         if (fnmatch('*phone*', $k)) {
                             $v = str_replace('+', '', $v);
                         }
                         $row->{$k} = $v;
                     }
                     $row->save();
                 }
             }
         }
         dd($row);
     }
 }
Ejemplo n.º 19
0
 public function discover_endpoint(Request $request, Response $response)
 {
     if (!$this->_is_logged_in($request, $response)) {
         return $response;
     }
     $targetURL = $request->get('target');
     if (!Telegraph\Webmention::isProbablySupported($targetURL)) {
         $status = 'none';
         $cached = -1;
     } else {
         // Cache the discovered result
         $cacheKey = 'telegraph:discover_endpoint:' . $targetURL;
         if ($request->get('ignore_cache') == 'true' || !($status = redis()->get($cacheKey))) {
             $client = new IndieWeb\MentionClient();
             $endpoint = $client->discoverWebmentionEndpoint($targetURL);
             if ($endpoint) {
                 $status = 'webmention';
             } else {
                 $endpoint = $client->discoverPingbackEndpoint($targetURL);
                 if ($endpoint) {
                     $status = 'pingback';
                 } else {
                     $status = 'none';
                 }
             }
             $cached = false;
             redis()->setex($cacheKey, 600, $status);
         } else {
             $cached = true;
         }
     }
     $response->headers->set('Content-Type', 'application/json');
     $response->setContent(json_encode(['status' => $status, 'cached' => $cached]));
     return $response;
 }
Ejemplo n.º 20
0
 protected function compiled($compile = false)
 {
     $viewRedis = container()->getViewRedis();
     if (true !== $viewRedis) {
         $file = CACHE_PATH . DS . md5($this->_viewFile) . '.compiled';
         if (false !== $compile) {
             if (File::exists($file)) {
                 File::delete($file);
             }
             File::put($file, $this->makeCompile($compile));
         }
         return $file;
     } else {
         $redis = redis();
         $keyAge = sha1($this->_viewFile) . '::age';
         $keyTpl = sha1($this->_viewFile) . '::html';
         if (false !== $compile) {
             $redis->set($keyAge, time());
             $content = $this->makeCompile($compile);
             $redis->set($keyTpl, $content);
             return $content;
         } else {
             return $redis->get($keyTpl);
         }
     }
 }
Ejemplo n.º 21
0
 public function sessionGet($k, $d = null)
 {
     $key = sha1(session_id() . $k);
     $value = redis()->get($key);
     return $value ? $value : $d;
 }
Ejemplo n.º 22
0
 public static function getCoords($address, $region = 'FR')
 {
     $key = 'loc.coords.' . sha1(serialize(func_get_args()));
     $coords = redis()->get($key);
     if (strlen($coords)) {
         return unserialize($coords);
     }
     $address = urlencode($address);
     $json = fgc("http://maps.google.com/maps/api/geocode/json?address={$address}&sensor=false&region={$region}");
     if (!strstr($json, 'geometry')) {
         return ['lng' => 0, 'lat' => 0];
     }
     $json = json_decode($json);
     $lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
     $lng = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
     $addrComponents = $json->{'results'}[0]->{'address_components'};
     $addrComponents = json_decode(json_encode($addrComponents), true);
     $components = [];
     foreach ($addrComponents as $component) {
         $k = implode('_', $component['types']);
         if ($k == 'locality_political') {
             $k = 'city';
         } elseif ($k == 'route') {
             $k = 'street';
         } elseif ($k == 'administrative_area_level_2_political') {
             $k = 'department';
         } elseif ($k == 'administrative_area_level_1_political') {
             $k = 'region';
         } elseif ($k == 'country_political') {
             $k = 'country';
         } elseif ($k == 'postal_code') {
             $k = 'zip';
         }
         unset($component['types']);
         $components[$k] = $component;
     }
     $components += ['lng' => $lng, 'lat' => $lat, 'geohash' => with(new Geohash())->encode($lat, $lng)];
     ksort($components);
     redis()->set($key, serialize($components));
     return $components;
 }
Ejemplo n.º 23
0
 public function orderBy($fieldOrder, $orderDirection = 'ASC')
 {
     $sortFunc = function ($key, $direction) {
         return function ($a, $b) use($key, $direction) {
             if ('ASC' == $direction) {
                 return $a[$key] > $b[$key];
             } else {
                 return $a[$key] < $b[$key];
             }
         };
     };
     if (Arrays::is($fieldOrder) && !Arrays::is($orderDirection)) {
         $t = array();
         foreach ($fieldOrder as $tmpField) {
             array_push($t, $orderDirection);
         }
         $orderDirection = $t;
     }
     if (!Arrays::is($fieldOrder) && Arrays::is($orderDirection)) {
         $orderDirection = Arrays::first($orderDirection);
     }
     if (Arrays::is($fieldOrder) && Arrays::is($orderDirection)) {
         for ($i = 0; $i < count($fieldOrder); $i++) {
             usort($this->_items, $sortFunc($fieldOrder[$i], $orderDirection[$i]));
         }
     } else {
         usort($this->_items, $sortFunc($fieldOrder, $orderDirection));
     }
     if ($this->_key != 'collection::') {
         redis()->hset($this->_key, sha1(serialize(func_get_args())), serialize($this->_items));
     }
     return $this;
 }
Ejemplo n.º 24
0
<?

restrict();

if (p('func') == 'change_password' && p('password')) {
	if (p('password') != p('confirm_password')) {
		error('Passwords don\'t match!');
	} else {
		redis()->set('schlage:password', p('password'));
		success('Password changed!');
		r('/password');
	}
} else {
	$schlage = Schlage::GetInstance();
	if ($schlage->Login()) {
		success('Your current password properly authenticates');
	} else {
		error('Your password cannot authenticate, please update it!');
	}
}


top();

h2('Change your password');

form();
label('New Password');
password('password');
label('Confirm Password');
password('confirm_password');
Ejemplo n.º 25
0
 public function commonLinkers($objects = [])
 {
     $objects[] = $this->object;
     $keys = [];
     foreach ($objects as $object) {
         $key = $this->makeKey($object);
         $keys[] = "g.{$key}.lb";
     }
     return call_user_func_array([redis(), 'sinter'], $keys);
 }
Ejemplo n.º 26
0
function isCached($k, callable $c, $maxAge = null, $args = [])
{
    $cached = redis()->get($k);
    if ($maxAge) {
        $age = redis()->get($k . '.age');
        if ($age) {
            if (time() > $age) {
                $cached = null;
            }
        } else {
            $cached = null;
        }
    }
    if (!$cached) {
        $data = call_user_func_array($c, $args);
        redis()->set($k, serialize($data));
        if ($maxAge) {
            if ($maxAge < 1444000000) {
                $maxAge = $maxAge * 60 + time();
            }
            redis()->set($k . '.age', $maxAge);
        }
    } else {
        $data = unserialize($cached);
    }
    return $data;
}
Ejemplo n.º 27
0
</div>

</body>

<script type="text/javascript" src="<?php 
echo getPathToStaticResource('/script/wz_tooltip.js');
?>
"></script>

<?php 
if (isset($_REQUEST["footerScripts"])) {
    foreach ($_REQUEST["footerScripts"] as $script) {
        print $script . "\n";
    }
}
?>

</html>

<?php 
$peak = memory_get_peak_usage();
workbenchLog(LOG_INFO, "MemoryUsageCheck", array("measure.memory.peak" => $peak . "byte"));
if (WorkbenchContext::isEstablished() && $peak / toBytes(ini_get("memory_limit")) > 0.7) {
    WorkbenchContext::get()->clearCache();
    workbenchLog(LOG_INFO, "MemoryUsageCacheClear", array("measure.memory.cache_clear" => 1));
}
if (isset($GLOBALS['REDIS'])) {
    redis()->close();
}
//USAGE: debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
debug(true, true, null, null);
Ejemplo n.º 28
0
                $aid = $data['uid'];
                $b = $data['data'];
                if ($aid && $b['openid']) {
                    $b['fd'] = $fd;
                    redis()->set($b['openid'], json_encode($b));
                    $a = json_decode(redis()->get($aid), true);
                    $result = $a['r'] ? $a['r'] : 0;
                    $r = $_server->push($a['fd'], json_enc_cn(['uid' => $b['openid'], 'data' => $b, 'action' => 'scan', 'result' => $result]));
                    if (!$r) {
                        $msg['err'] = 'a已经离线,发送失败';
                        $_server->push($fd, json_enc_cn($msg));
                        return;
                    }
                    $_server->push($fd, json_enc_cn(['uid' => $aid, 'data' => $a, 'action' => 'scan', 'result' => $result]));
                    $a['r'] = 1;
                    redis()->set($aid, json_encode($a));
                } else {
                    $data['err'] = '数据格式错误';
                    $_server->push($fd, json_enc_cn($data));
                }
            }
        }
    }
    //	$_server->close($frame->fd);
});
$server->on('close', function ($_server, $fd) {
    echo "client {$fd} closed\n";
});
$server->on('request', function (swoole_http_request $request, swoole_http_response $response) {
    $response->end(<<<HTML
HTML
Ejemplo n.º 29
0
 private function waitUnlock($action)
 {
     if (true === $this->locked) {
         if (true === $this->debug) {
             container()->log("wait " . $action);
         }
         $wait = !is_null(redis()->get($this->lock));
         $i = 1;
         while (true == $wait) {
             if (1000 == $i) {
                 $this->unlock('forced ' . $action);
             }
             usleep(100);
             $wait = !is_null(redis()->get($this->lock));
             $i++;
         }
     }
     return $this;
 }
Ejemplo n.º 30
0
 public function geonames($lat, $lng)
 {
     $key = 'geonames.' . sha1($lat . '.' . $lng);
     $json = redis()->get($key);
     if (!$json) {
         $json = dwn('http://scatter-otl.rhcloud.com/location?lat=' . $lat . '&long=' . $lng);
         redis()->set($key, $json);
     }
     return json_decode($json, true);
 }