PHP 真正多线程的使用

| |
[不指定 2013-12-17 11:17 | 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多线程的作用非常明显。


  1、扩展的编译安装(Linux),编辑参数 --enable-maintainer-zts 是必选项:
cd /Data/tgz/php-5.5.1
./configure --prefix=/Data/apps/php --with-config-file-path=/Data/apps/php/etc --with-mysql=/Data/apps/mysql --with-mysqli=/Data/apps/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir=/Data/apps/libs --with-jpeg-dir=/Data/apps/libs --with-png-dir=/Data/apps/libs --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/Data/apps/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts
make clean
make install        

cd pthreads-master
./configure --with-php-config=/Data/apps/php/bin/php-config
make install

vi /Data/apps/php/etc/php.ini

extension = ""


技术大类 » PHP/JS/Shell | 评论(227) | 引用(0) | 阅读(419099)
mstony Email
2022-10-28 06:52
MTOVER Email Homepage
2022-10-28 12:24
This is the info I was looking for. I saw a very good article. I will visit you often in the future. Thanks for the good article.은꼴
moz1 Email Homepage
2022-11-3 15:43
Online slots (Slot) is one of the gambling games that are   autowin888   popular with online gamblers. Playing slots has been around for a long time. But online slots have evolved from offline casino slot machines. Which playing online slots has opened up for a short time, but there are many people who are interested in gambling online. Just having internet can start playing easily.
ogwhatsapp Email Homepage
2022-12-4 00:05
There is a saying about this app that the first thing people do after getting their mobile phones is install this application.ogwhatsapp is basically an extended version of the WhatsApp application.
mymro Homepage
2022-12-8 15:24
MyMRO is a specialized and leading brand for supplying construction and agriculture machinery parts for customers worldwide, along with the belief of standing on large variety, fast delivery, OEM quality, and the lowest price.  At MyMRO, always have what you need, always at low prices. We are proud of our delivery, specialist service, quality, and pricing that always meets and exceeds our customers' expectations.In addition to cost of ignition switch, you can also buy other models or other parts of Excavators, Forklift, Aerial Work Platforms AWP on our website.
mtguide Email Homepage
2022-12-9 23:43
2023-1-18 21:42
I find this so interesting and cool. Keep sharing! Appliance Removal Joliet IL
fouadwhatsapp Email Homepage
2023-1-24 16:30
In this modern era of social media, everyone especially youngsters is well aware of the amazing messaging platform called fouad whatsapp download. Due to its popularity all around the globe, a plethora of modified forms of WhatsApp has been introduced such as FM WhatsApp, GB WhatsApp, Yo WhatsApp, and many others.
slajobs3141 Email Homepage
2023-2-3 19:38
I had no prior knowledge of the topic, but thanks to the article, I quickly grasped it. Beginners like me would gain a lot of knowledge from this blog. Many thanks.Full stack training in Chennai
Jim Email Homepage
2023-2-5 00:28
Maximizing the Well-being of Our Furry Companions: Tips and Tricks for Caring for Cats, Dogs, and Other Animals.
Animal world

Discover the latest strategies for making money online and maximizing your ROI. All aspects of SEO, including keyword research, Link Building !
LGC Strategies
메이저사이트 Email Homepage
2023-3-7 08:13
It is an honor to be able to read an article where you can feel the fun of finding a topic in the text메이저사이트
먹튀검증 Email Homepage
2023-3-7 08:13
Looking at your witty article, I also came up with an idea. I want to learn that. I will visit your blog often.먹튀검증
nerrty Email
2023-4-12 10:47
It is now much simpler to track and trace the packages you have sent through the United States Postal Service (USPS). To check the current position of your shipment, simply add the usps tracking number to the post tracking form.
jen Email Homepage
2023-5-9 22:10
Thank you so muchGetRewardsNowGiftcard
2023-5-17 04:04
これは助かります..Joseph R.
WER Email
2023-6-12 00:37
Check it out!<a href="">dh</a> |esc
WER Email
2023-6-12 00:38
VİP - escort girls in baku  |
baku Email
2023-6-12 02:05
best baku vip escort girls in baku
megeorge Email
2023-6-15 04:01
SerenaFabbri Email
2023-7-12 12:12
Dengan bermain slot online bersama poker88 link alternatif maka bersiaplah untuk pengalaman bermain dengan kejutan dan hadiah. Slot poker88 asia sudah sangat teruji sangat terpercaya dan banyak pencinta slot online betah dalam permainan-permainan seru kami.
分页: 11/12 第一页 上页 6 7 8 9 10 11 12 下页 最后页
昵称   密码   游客无需密码
网址   电邮   [注册]