The use of Taobao IP interface to determine whether IP, is the domestic IP, is the domestic (CN) is not allowed access.
$ip = $_server[' remote_addr '];
$content = file_get_contents (' http://ip.taobao.com/service/getIpInfo.php?ip= '. $ip);
$banned = Json_decode (Trim ($content), true);
$lan = Strtolower ($_server[' http_accept_language '));
if (!empty ($banned [' Data '] [' country_id ']) && $banned [' Data '] [' country_id '] = = ' CN ') | | strstr ($lan, ' en '))
{
header ("http/1.0 404 Not Found");
echo ' http/1.0 404 Not Found ';
Exit;
}
Also found a good article: http://luhuang.sinaapp.com/redis-setnx/"Redis to limit high concurrent PHP code example"
Redis is essentially a key-value database, but it also absorbs the advantages of some relational databases while maintaining the simple and quick features of key-valued databases. So that it is positioned between the relational database and the key value database. Redis not only can save strings type of data, but also can save lists type (ordered) and sets type (unordered) data, but also can complete sorting (sort) and other advanced functions, in the implementation of functions such as incr,setnx to ensure the atomic nature of its operations, in addition, also supports the master-slave replication and other functions.
Redis to limit high concurrency
PHP Code Instance
$redis->setnx (' Lock:hot_items ', true) tries to create a key as a "lock." If key already exists,
SETNX does not do any action and the return value is false, so only one client returns a true value into the IF statement to update the cache.
$redis = new Redis ();
$redis _key = ' lock:hot_items ';
$clock _expire_time = $redis->get ($redis _key); if (!empty ($clock _expire_time) && time () > Intval ($clock _expire_time)) {//unlock current Redis lock $redis->delete ($
Redis_key);
} if ($redis->setnx ($redis _key, Time () + 3)!== true) {echo ' High concurrency conflict ';}
Manipulate your code, at the same time a person accesses the code//unlocks the current Redis lock $redis->delete ($redis _key);