PHP读取文本文件 换行尾巴的问题


这个文本文件 如果编码不一样

$lines = file(‘file.txt’);
$string = str_replace(array(“\r”, “\n”), ”, $lines)

$lines = file(‘file.txt’, FILE_IGNORE_NEW_LINES);

如果需要去掉空行 可以这样
$lines = file(‘file.txt’, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

$file = ‘newline.txt’;
$data = file_get_contents($file);
$lines = explode(PHP_EOL, $data);

PHP 最简单的API 请求频率限制 方式

例如 限制 API 每秒仅允许请求一次


加限制以后 这样

这个适合小应用使用 其他规模的还是使用 


换个思路替换数组里的关键词,非array_replace或者array_key array_fill方式

只是需要替换规律一个固定的关键词 保证其他内容的原汁原味



变量没附值 原生php也就出现个警告 结果框架直接终止抛出异常



PHP Redis 限制API和各种接口 请求频率

PHP Redis 限制API和各种接口 请求频率



sql那块 尽量使用pdo
实在不习惯 使用sql的封装也可以的 比如 adodb 封装好的

使用 Memcache/Redis 缓存 MYSQL的查询和更新 降低mysql的连接率开销

Memcache 缓存 MYSQL的查询 降低mysql的连接率
使用 Memcache/Redis 缓存 MYSQL的查询和更新 降低mysql的连接率开销

其实大部分的mysql查询 都是可以被短期缓存的
这种在大流量并发的情况下 可以非常有效的降低查询开销

这里介绍2种场景 使用Memcache来缓存
第一种 查询数据

第二种 更新数据
这种固定在更新数字上 例如 帖子 被点击+1 用户访问页数 +1
通常会直接更新mysql 每次+1 都要connection mysql 然后update 操作
小流量当然无所谓 但是大流量的情况 就非常耗费资源了
使用缓存 可以这样做 达到一个量级 在一次性更新 比如点击数缓存已经达到50 就更新一次点击数
这样本来想要connection 50次mysql + update 50次+1 就变为 connection 1次 + update 1次+50
开销当然降低了 对吧

以Redis来做例子 和Memcache/ SSDB / levelDB 都类似 差别不大

PHP baidu 翻译 Web模拟接口 非API 永久免费

PHP baidu 翻译 Web模拟接口 非API 永久免费

PHP baidu 翻译 Web模拟接口 非API 永久免费
PHP baidu 翻译 Web模拟接口 非API 永久免费

< ?php $a = 'hi, this my account'; echo sfanyi($a); function sfanyi($content){ if(!$content == NULL) { $apiurl = ""; $text = array('ie' => "utf-8",
'source' =>"txt",
'query' => $content,
't' => time(),
'token' => "",
'from' => "en",
'to' => "zh"
$fields_string = '';
foreach($text as $key=>$value) {
$fields_string .=$key.'='.$value.'&';
rtrim($fields_string, '&');
//echo $fields_string;
$queryurl = $apiurl; //.$query;
$ch = curl_init ($queryurl);
//curl_setopt ($ch,CURLOPT_COOKIEFILE, $ckfile);
curl_setopt ($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch,CURLOPT_REFERER,'');
curl_setopt ($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22');
curl_setopt ($ch,CURLOPT_POST, count($text));
curl_setopt ($ch,CURLOPT_POSTFIELDS, $fields_string);
$data = curl_exec ($ch);
$out = json_decode($data,true);
return $out['data']['0']['dst']; //$data;
}else {
return false;

PHP 7.0 正式发布了

Today, we’re pleased to announce that PHP 7.0 – the fastest and most efficient PHP ever – is officially released!

PHP 7.0 brings you unprecedented levels of real-world performance and throughput by utilizing the new and advanced Zend Engine 3.0, designed and refactored for speed and reduced memory consumption. This translates to real-world benefits: greatly decreased response times, superior user experiences, and the ability to serve more users with fewer servers to maximize the power of your PHP 7.0 deployment.

The explosive performance improvements of PHP 7.0 range between 50% and 200% on real-world apps – without changing a single line of code:


PHP 7.0.0 comes with a new version of the Zend Engine, numerous improvements and new features such as

Improved performance: PHP 7 is up to twice as fast as PHP 5.6
Significantly reduced memory usage
Abstract Syntax Tree
Consistent 64-bit support
Improved Exception hierarchy
Many fatal errors converted to Exceptions
Secure random number generator
Removed old and unsupported SAPIs and extensions
The null coalescing operator (??)
Return and Scalar Type Declarations
Anonymous Classes
Zero cost asserts

cd /opt
wget -c
tar xfz php*.tar.gz
cd php*
configure 加一堆参数就可以了


I have successfully installed and integrate MySQL Cluster with HAproxy and Keepalived to provide scalable MySQL service with cPanel server run on CentOS 6.3 64bit. As you guys know that cPanel has a function called “Setup Remote MySQL server” which we can use to remotely access and control MySQL server from cPanel.

This will bring a big advantage, because the cPanel server load will be reduced tremendously due to mysqld service and resource will be serve from a cluster of servers. Following picture shows my architecture:


I will be using following variables:

OS: CentOS 6.3 64bit
WHM/cPanel version: 11.34.0 (build 11)
MySQL root password: MhGGs4wYs


仿 源码 多地点Ping源码 多节点ping延时测试 源码

仿 源码 国际版

多地点Ping源码 多节点ping延时测试 源码

主要是由多节点返回测试数据 获得大致的延时数据 推测出网络状况
基于SQLITE数据库 没有后台 直接Web sqlite 编辑数据即可



NLAmsterdam440147 ms147 ms147 ms
ROBukarest440179 ms187 ms183 ms
ATVienna440156 ms156 ms156 ms
USTX Dallas44060 ms60 ms60 ms
DEFrankfurt440145 ms145 ms145 ms
USNY New York44065 ms65 ms65 ms
USTX Dallas44060 ms60 ms60 ms
USOR RoseBurg44020 ms21 ms20 ms
SEGothenburg440178 ms178 ms178 ms
DENürnberg440153 ms153 ms153 ms
BGVarna440182 ms182 ms182 ms
AUAdelaide440184 ms185 ms184 ms
USCA San Jose44033 ms33 ms33 ms
FRParis440140 ms141 ms141 ms
CanadaMontreal44073 ms73 ms73 ms
BEOostkamp440144 ms145 ms145 ms
ITMilano440154 ms155 ms154 ms
INPune440213 ms217 ms215 ms
SEStockholm440167 ms168 ms167 ms
RUSaint-Petersburg440192 ms194 ms193 ms
PLWarschau440161 ms162 ms161 ms
FLBalzers440161 ms161 ms161 ms
USCO Denver44050 ms50 ms50 ms
ESAlicante440164 ms165 ms164 ms
ILTel Aviv440199 ms199 ms199 ms
DEFrankfurt440145 ms145 ms145 ms
LVRiga440180 ms180 ms180 ms
USNJ Edison44072 ms72 ms72 ms
USNY Buffalo44076 ms77 ms77 ms
ESMadrid440152 ms152 ms152 ms
USAZ Scottsdale44053 ms54 ms53 ms
CNHong Kong440161 ms161 ms161 ms
UKLondon440141 ms141 ms141 ms
CHLausanne440155 ms155 ms155 ms
IEHafnarfjordur440193 ms216 ms199 ms
PLŻywiec440172 ms172 ms172 ms
USIL Chicago44070 ms71 ms70 ms
USFL Jacksonville44089 ms89 ms89 ms
USTX Dallas44062 ms62 ms62 ms
SGSingapore440153 ms153 ms153 ms
TWTaichung440136 ms136 ms136 ms
CLChile440180 ms187 ms182 ms
NLAmsterdam440146 ms146 ms146 ms
DEFrankfurt440145 ms145 ms145 ms
NLHolland440146 ms146 ms146 ms
CHZurich440151 ms151 ms151 ms
IMDouglas440147 ms147 ms147 ms
USMO Kansas City44056 ms56 ms56 ms
SEGothenburg440178 ms178 ms178 ms
RUMoskau440192 ms423 ms250 ms
USCA San Jose44040 ms40 ms40 ms
USNV Las Vegas44035 ms36 ms35 ms
USGA Atlanta44085 ms86 ms86 ms
USCA Los Angeles44030 ms30 ms30 ms
AUSydney440164 ms164 ms164 ms
USDC Seattle4408 ms8 ms8 ms