by 张宴 PHP 5.3 以上版本,使用pthreads PHP扩展,可以使PHP真正地支持多线程。多线程在处理重复性的循环任务,能够大大缩短程序执行时间。 我之前的文章中说过,大多数网站的性能瓶颈不在PHP服务器上,因为它可以简单地通过横向增加服务器或CPU核数来轻松应对(对于各种云主机,增加 VPS或CPU核数就更方便了,直接以备份镜像增加VPS,连操作系统、环境都不用安装配置),而是在于MySQL数据库。如果用 MySQL 数据库,一条联合查询的SQL,也许就可以处理完业务逻辑,但是,遇到大量并发请求,就歇菜了。如果用 NoSQL 数据库,也许需要十次查询,才能处理完同样地业务逻辑,但每次查询都比 MySQL 要快,十次循环NoSQL查询也许比一次MySQL联合查询更快,应对几万次/秒的查询完全没问题。如果加上PHP多线程,通过十个线程同时查询 NoSQL,返回结果汇总输出,速度就要更快了。我们实际的APP产品中,调用一个通过用户喜好实时推荐商品的PHP接口,PHP需要对BigSea NoSQL数据库发起500~1000次查询,来实时算出用户的个性喜好商品数据,PHP多线程的作用非常明显。
最新文章
by 张宴 With PHP 5.3 and above, using the pthreads PHP extension lets PHP truly support multithreading. When handling repetitive loop tasks, multithreading can greatly shorten program execution time. As I said in a previous article of mine, the performance bottleneck of most websites is not the PHP server, because that can be easily handled by simply scaling out with more servers or more CPU cores (for the various cloud hosts, adding VPS instances or CPU cores is even more convenient — you just add a VPS from a backup image, and you don’t even have to install or configure an operating system or environment). The bottleneck is the MySQL database. If you use a MySQL database, a single join query in SQL might be enough to handle the business logic, but when you run into a large number of concurrent requests, it falls apart. If you use a NoSQL database, you might need ten queries to handle the same business logic, but each query is faster than MySQL — ten NoSQL queries in a loop may well be faster than one MySQL join query, and handling tens of thousands of queries per second is no problem at all. Add PHP multithreading on top, querying NoSQL with ten threads at the same time and aggregating the returned results for output, and it gets even faster. In our actual APP product, calling a single PHP interface that recommends products in real time based on user preferences requires PHP to issue 500~1000 queries to the BigSea NoSQL database in order to compute the user’s personalized preferred product data in real time — the effect of PHP multithreading is very obvious here.
作者: 阮一峰 “数据可视化”可以帮助用户理解数据,一直是热门方向。 图表是”数据可视化”的常用手段,其中又以基本图表——柱状图、折线图、饼图等等——最为常用。
用户非常熟悉这些图表,但如果被问道,它们的特点是什么,最适用怎样的场合(数据集)?恐怕答得上来的人就不多了。 本文是电子书《Data Visualization with JavaScript》第一章的笔记,总结了六种基本图表的特点和适用场合,非常好地回答了上面的问题。
零、序言
进入正题之前,先纠正一种误解。 有人觉得,基本图表太简单、太原始,不高端,不大气,因此追求更复杂的图表。但是,越简单的图表,越容易理解,而快速易懂地理解数据,不正是”数据可视化”的最重要目的和最高追求吗? 所以,请不要小看这些基本图表。因为用户最熟悉它们,所以只要是适用的场合,就应该考虑优先使用。
Author: 阮一峰 “Data visualization” helps users understand data, and has always been a hot direction. Charts are a common means of “data visualization”, among which the basic charts——bar chart, line chart, pie chart and so on——are the most commonly used.
Users are very familiar with these charts, but if asked what their characteristics are and which occasions (data sets) they suit best, probably not many people could answer. This article is a note on the first chapter of the e-book 《Data Visualization with JavaScript》, summarizing the characteristics and applicable occasions of six basic charts, and answering the above question very well.
Zero. Preface
Before getting to the point, let me first correct a misconception. Some people feel that basic charts are too simple, too primitive, not high-end or impressive, and therefore pursue more complex charts. But the simpler the chart, the easier it is to understand, and quickly and easily understanding data is precisely the most important purpose and highest pursuit of “data visualization”, isn’t it? So please don’t look down on these basic charts. Because users are most familiar with them, wherever they are applicable you should consider using them first.
PHP是一种弱类型语言, 这样的特性, 必然要求有无缝透明的隐式类型转换, PHP内部使用zval来保存任意类型的数值, zval的结构如下(5.2为例):1
2
3
4
5
6
7struct \_zval\_struct {
/\* Variable information */
zvalue_value value; /\* value */
zend_uint refcount;
zend_uchar type; /\* active type */
zend_uchar is_ref;
};
PHP is a weakly typed language, and this characteristic inevitably requires seamless and transparent implicit type conversion. Internally, PHP uses zval to store values of any type. The structure of zval is as follows (5.2 as an example):1
2
3
4
5
6
7struct \_zval\_struct {
/\* Variable information */
zvalue_value value; /\* value */
zend_uint refcount;
zend_uchar type; /\* active type */
zend_uchar is_ref;
};
解压 语法:tar [主选项+辅选项] 文件或者目录 使用该命令时,主选项是必须要有的,它告诉tar要做什么事情,辅选项是辅助使用的,可以选用。
主选项:
c 创建新的档案文件。如果用户想备份一个目录或是一些文件,就要选择这个选项。相当于打包。
x 从档案文件中释放文件。相当于拆包。
t 列出档案文件的内容,查看已经备份了哪些文件。
特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!因为不可能同时压缩与解压缩。
Extraction Syntax: tar [main options + auxiliary options] file or directory. When using this command, the main option is mandatory — it tells tar what to do. The auxiliary options are supporting ones and are optional.
Main options:
c Create a new archive file. If the user wants to back up a directory or some files, this is the option to choose. Equivalent to packing.
x Release files from the archive file. Equivalent to unpacking.
t List the contents of the archive file, to see which files have already been backed up.
Note in particular that among the parameters issued, only one of c/x/t can exist! They cannot exist at the same time! Because it’s impossible to compress and decompress at the same time.
正则表达式是程序开发中一个重要的元素,它提供用来描述或匹配文本的字符串,如特定的字符、词或算式等。但在某些情况下,用正则表达式去验证一个字符串比较复杂和费时。本文为你介绍10种常见的实用PHP正则表达式的写法,希望对你的工作有所帮助。 1. 验证E-mail地址 这是一个用于验证电子邮件的正则表达式。但它并不是高效、完美的解决方案。在此不推荐使用。
Php代码1
2
3
4
5
6$email = "test@ansoncheung.tk";
if (preg_match('/^\[^0-9\]\[a-zA-Z0-9_\]+(\[.\]\[a-zA-Z0-9_\]+)*\[@\]\[a-zA-Z0-9_\]+(\[.\]\[a-zA-Z0-9_\]+)*\[.\]\[a-zA-Z\]{2,4}$/',$email)) {
echo "Your email is ok.";
} else {
echo "Wrong email address format";
}
Regular expressions are an important element in program development; they provide strings used to describe or match text, such as specific characters, words, or expressions. But in some cases, using a regular expression to validate a string is fairly complicated and time-consuming. This article introduces 10 common and practical ways to write PHP regular expressions, and I hope they are helpful in your work. 1. Validate an E-mail address This is a regular expression used to validate email. But it is not an efficient, perfect solution. Its use is not recommended here.
Php code1
2
3
4
5
6$email = "test@ansoncheung.tk";
if (preg_match('/^\[^0-9\]\[a-zA-Z0-9_\]+(\[.\]\[a-zA-Z0-9_\]+)*\[@\]\[a-zA-Z0-9_\]+(\[.\]\[a-zA-Z0-9_\]+)*\[.\]\[a-zA-Z\]{2,4}$/',$email)) {
echo "Your email is ok.";
} else {
echo "Wrong email address format";
}
12月8日消息,亚马逊集团董事会主席兼CEO杰夫·贝佐斯(Jeff Bezos)表示,亚马逊将会发布更多款的智能手机。外界希望他能从亚马逊Fire Phone的惨痛失败中接受教训并汲取经验。这款手机的失败导致亚马逊从众多手机制造商中脱颖而出的想法变得愈加难以实现。 关于亚马逊的Fire Phone,有两点值得注意。
News from December 8: Amazon chairman and CEO Jeff Bezos says Amazon will release more smartphones. The outside world hopes he has taken the lessons of the Fire Phone’s painful failure to heart. That failure has made Amazon’s ambition of standing out from the crowd of phone makers harder and harder to realize. There are two things worth noting about the Amazon Fire Phone.
前言:我只实现了利用james来发送邮件,至于接收邮件没有测试过。
网上的资料有很多,感兴趣的话也可以搜索一下。我也是根据网上的资料,进行汇总并尝试,思考后写的文章,里面引用了网上的部分资料。无废话,开始干~
Preface: I only got as far as using james to send email; I never tested receiving mail.
There is plenty of material online — search around if you’re interested. I too gathered material from the web, tried things out, thought it over, and then wrote this article, which quotes some of that material. No waffle, let’s get to work~
一.水平分割 什么是水平分割?打个比较形象的比喻,在食堂吃 饭的时候,只有一个窗口,排队打饭的队伍太长了,都排成S型了,这时容易让排队的人产生焦虑情绪,容易产生混乱,这时一个管理者站出来,增加多个打饭窗 口,把那条长长的队伍拦腰截断成几队。更形象一点的理解,你拿一把“手术刀”,把一个大表猛的切了几刀,结果这个大表,变成了几个小表. 水平分割根据某些条件将数据放到两个或多个独立 的表中。即按记录进分分割,不同的记录可以分开保存,每个子表的列数相同。水平切割将表分为多个表。每个表包含的列数相同,但是数据行更少。
1. Horizontal Partitioning What is horizontal partitioning? A rather vivid analogy: when you eat in a canteen there is only one window, and the queue for food gets so long that it coils into an S shape, which easily makes the people in line anxious and prone to chaos. Then a manager steps up, adds several more serving windows, and cuts that long queue in half into several lines. To put it even more vividly: you take a “scalpel” and slash a big table a few times, and the big table turns into several small tables. Horizontal partitioning places data into two or more independent tables according to certain conditions. That is, it partitions by records — different records can be stored separately, and each sub-table has the same number of columns. Horizontal splitting divides a table into multiple tables. Each table contains the same number of columns, but fewer data rows.
最近一直在开发一个中型项目,就用onethink了,后来发现路径优化问题老是困扰,反复百度查询后,今早突然变好了。 反复分析一下原因,原来是没清楚缓存。 具体更改方法如下 首先找到公共config.php文件,在项目Application\Common\Conf下,在 代码如下
'MODULE\_ALLOW\_LIST' => array('Home','Admin'),
'URL\_ROUTER\_ON' => true,
'URL\_ROUTE\_RULES'=>array(
'index' => 'Index/index', //首页
'article/:id\\d$' => 'Article/detail', //文章页
':category$'=> 'Article/lists' //列表页 ),
然后在找到URL_MODEL把后面的3改为2,同时复制这一行代码 粘贴到Application\Home\Conf下的confi.php 代码如下
'URL\_MODEL' => 2, //URL模式
然后清空缓存,缓存位置在项目Runtime\Cache\Home文件下删除所有的文件 刷新浏览器后路径中home不见了。 笔者在这想说onethink框架还是不错的,基于thinkphp3.2开发的,非常便捷。
I’ve been developing a medium-sized project for a while now, and I used onethink for it. Later I found that the path optimization issue kept bugging me; after searching on Baidu over and over, it suddenly worked this morning. After analyzing the reason again and again, it turned out I simply hadn’t cleared the cache. The specific way to change it is as follows. First find the common config.php file, which is under Application\Common\Conf in the project, and in it the code is as follows
'MODULE\_ALLOW\_LIST' => array('Home','Admin'),
'URL\_ROUTER\_ON' => true,
'URL\_ROUTE\_RULES'=>array(
'index' => 'Index/index', //首页
'article/:id\\d$' => 'Article/detail', //文章页
':category$'=> 'Article/lists' //列表页 ),
Then find URL_MODEL and change the 3 after it to 2, and at the same time copy this line of code and paste it into confi.php under Application\Home\Conf. The code is as follows
'URL\_MODEL' => 2, //URL mode
Then clear the cache — the cache is under Runtime\Cache\Home in the project, so delete all the files in there. After refreshing the browser, home is gone from the path. Here I’d like to say that the onethink framework is still a good one; it’s built on thinkphp3.2 and is very convenient.
回想一下学习php这么久以来,刚开始那会一直搞不懂类、内部属性、外部属性现在从头来个详细的介绍。 代码如下 <?php header(“content-type:text/html;charset=utf-8”); class guests{//声明一个类guests private $name; //私有属性 private $gender; function setname($name){ $this->name=$name; } function getname(){ return $this->name; //返回姓名 } function setgender($gender){ $this->gender=$gender; } function getgender(){ return $this->gender; //返回性别 } }; $xiaoming=new guests; $xiaoming->setname(“王小明”); $xiaoming->setgender(“男”); $lili=new guests; $lili->setname(“莉莉”); $lili->setgender(“女”); echo $xiaoming->getname().”\t”.$xiaoming->getgender().”
“; echo $lili->getname().”\t”.$lili->getgender(); ?>
Thinking back over how long I have been learning PHP, at the very beginning I never could figure out classes, internal properties, and external properties. So now let’s go through a detailed introduction from the start. The code is as follows <?php header(“content-type:text/html;charset=utf-8”); class guests{//declare a class guests private $name; //private property private $gender; function setname($name){ $this->name=$name; } function getname(){ return $this->name; //return the name } function setgender($gender){ $this->gender=$gender; } function getgender(){ return $this->gender; //return the gender } }; $xiaoming=new guests; $xiaoming->setname(“王小明”); $xiaoming->setgender(“男”); $lili=new guests; $lili->setname(“莉莉”); $lili->setgender(“女”); echo $xiaoming->getname().”\t”.$xiaoming->getgender().”
“; echo $lili->getname().”\t”.$lili->getgender(); ?>