

使用PHP做 http pxory 缓存&代理, 使用redis做缓存,支持毫秒过期,拥有超高性能
source link: https://blog.p2hp.com/archives/9308
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用PHP做 http pxory 缓存&代理, 使用redis做缓存,支持毫秒过期,拥有超高性能
使用PHP做 http pxory 缓存&代理, 使用 redis 做缓存,支持毫秒过期,拥有超高性能
<?php //PHP http pxory 缓存&代理, 使用redis做缓存,支持毫秒过期,拥有超高性能 $url=@$_GET['url']; if (empty($_GET['url'])) { echo 'url is empty '; exit; } $path=parse_url($url, PHP_URL_PATH); $key=$path; $redis = new Redis(); $redis->pconnect('127.0.0.1', 6379); if ($content=$redis->get($key)) { echo $content; exit; } // Client $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_NOSIGNAL, 1); //注意,毫秒超时一定要设置这个 curl_setopt($ch, CURLOPT_TIMEOUT_MS, 500); //超时毫秒,cURL 7.16.2中被加入。从PHP 5.2.3起可使用 $data = curl_exec($ch); $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); curl_close($ch); if ($curl_errno > 0) { echo "cURL Error ($curl_errno): $curl_error\n"; } else { // $redis->setEx('key', 3600, 'value');//以秒为单位 $redis->pSetEx($key, 50000, $data); // 将参数中的字符串值设置为键的值,并带有生存时间 pSetEx以毫秒为单位. echo $data; exit; }
使用方法:
http://localhost/proxy.php?url=https://www.xxxxxxx.com:3004/rooms/5f392ac745f6cd207b5301db
经压力测试,性能超高.!!
Recommend
-
61
不要短时间大量重复读写相同的key server端的原理是网络收包后,放入到工作队列(读写队列分离,但都只有一个),再由工作线程从队列中取出进行处理。这里一个问题是,为保证数据的正确性,会对同一个key的读写加锁,而如果存在大量读写同一个key的情况,则势必会...
-
69
-
53
-
47
-
49
-
20
缓存过期策略+Redis内存淘汰机制 作为一种定期清...
-
6
一日一技:实现有过期时间的LRU缓存 发表于 2020-03-23
-
6
使用 Nginx 缓存代理使您的后端更可靠 我们大多数人都...
-
9
缓存过期策略 定时删除 没人用 含义:在设置key的过期时间的同时,为该key创建一个定时器,让定时器在key的过期时间来临时,对key进行删除 优点:该策略可以立即清除过期的数据, 保证内存被尽...
-
5
使用Redis和Go实现高性能缓存 - 极道 Go 是构建高
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK