php多线程安装pthreads步骤详解

PHP扩展下载:https://github.com/krakjoe/pthreads
PHP手册文档:http://php.net/manual/zh/book.pthreads.php
安装脚本

 代码如下 复制代码
#!/bin/sh
cd /web/soft/php
if [ -d "pthreads-master" ];then
rm -rf pthreads-master
fi
unzip pthreads-master.zip
cd pthreads-master
/web/server/php/bin/phpize
./configure --with-php-config=/web/server/php/bin/php-config
make
make install
rm -rf pthreads-master
PHPINI="/web/server/php/etc/php.ini"
sed -i '907a extension = "pthreads.so"' $PHPINI
#更新php-fpm配置
sed -i 's%;pid = run/php-fpm.pid%pid = run/php-fpm.pid%' /web/server/php/etc/php-fpm.conf
sed -i 's%;error_log = log/php-fpm.log%error_log = log/php-fpm.log%' /web/server/php/etc/php-fpm.conf
#杀死php-fpm进程
ps aux | grep "php" | grep -v "grep" | awk '{print $2}' | xargs -i kill -9 {}
#启动php-fpm
/web/server/php/sbin/php-fpm
在安装过程中出现错误
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers

解决方法是安装或升级re2c 0.13.4以上版本。
下面我们用rpm包安装此库。
centos-5 32位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el5.rf.i386.rpm
centos-5 64位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el5.rf.x86_64.rpm
centos-6 32位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el6.rf.i686.rpm
centos-6 64位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el6.rf.x86_64.rpm
configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled
原因: 我在编译php的时候没有加入 --enable-maintainer-zts ,这个必须要重新编译php,不能动态加载的!
于是我重新编译了php,在原来的编译参数基础上那个加入了 --enable-maintainer-zts ,重新编译安装php即可!
以下为一个示例

 代码如下 复制代码
class test_thread_run extends Thread
{
public $url;
public $data;
public function __construct($url)
{
$this->url = $url;
}
public function run()
{
if(($url = $this->url))
{
$this->data = model_http_curl_get($url);
}
}
}
function model_thread_result_get($urls_array)
{
foreach ($urls_array as $key => $value)
{
$thread_array[$key] = new test_thread_run($value["url"]);
$thread_array[$key]->start();
}
foreach ($thread_array as $thread_array_key => $thread_array_value)
{
while($thread_array[$thread_array_key]->isRunning())
{
usleep(10);
}
if($thread_array[$thread_array_key]->join())
{
$variable_data[$thread_array_key] = $thread_array[$thread_array_key]->data;
}
}
return $variable_data;
}
function model_http_curl_get($url,$userAgent="")
{
$userAgent = $userAgent ? $userAgent : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
for ($i=0; $i < 100; $i++)
{
$urls_array[] = array("name" => "baidu", "url" => "http://www.111cn.net/ s?wd=".mt_rand(10000,20000));
}
$t = microtime(true);
$result = model_thread_result_get($urls_array);
$e = microtime(true);
echo "多线程:".($e-$t)."\n";
$t = microtime(true);
foreach ($urls_array as $key => $value)
{
$result_new[$key] = model_http_curl_get($value["url"]);
}
$e = microtime(true);
echo "For循环:".($e-$t)."\n";
?>
时间: 2024-09-20 13:36:19

php多线程安装pthreads步骤详解的相关文章

php5.3.10的安装配置步骤详解

在linux中php安装配置与windows中有不小的区别了,在linux中几乎都是代码形式了,下面我们一起来看看php5.3.10的安装配置步骤详解,希望下文可帮助到各位. 下面以最新的php-5.3.10为例进行安装. wget http://cn.php.net/distributions/php-5.3.10.tar.gz tar -zxvf php-5.3.10.tar.gz cd php-5.3.10 ./configure --prefix=/usr/local/php --wit

centos6中gitolite安装配置步骤详解

git服务端的管理工具用过2个,一个gitlab,一个是gitolite, 1,gitlab功能强大,有web管理界面,反正是各种方便吧,请参考:linux gitlab nginx 安装 配置 详解,但是gitlab安装比较麻烦 2,gitolite,安装非常简单,功能也比较简单,基本需要能满足,创建仓库,分配权限,总体来说还不错. 如果频繁的创建仓库,以及人员变更,用gitlab比较合适的,反之gitolite比较合适. 一,安装GIT # yum install perl openssh

Apache的mod_deflate模块安装配置步骤详解

最近把博客从虚拟主机搬到 VPS 上,自然一番折腾.估计围绕这一过程,写三四篇博客不是梦. 这是第一篇,服务器端的压缩功能 – 服务器在返回内容前先对内容做 gzip 压缩,以减小传输的文件大小 – 照 Google 的说法,能减小 90%,但这也不是重点,重点是服务器端不开启 gzip 压缩的话,Google PageSpeed 的测试就会扣分 – 我个人特别在意这个分数. Apache 下,压缩功能由 mod_deflate 模块控制. 安装# 我的 VPS 系统装的是 openSUSE 1

centos下Nginx安装配置步骤详解

nginx可以使用各平台的默认包来安装,本文是介绍使用源码编译安装,包括具体的编译参数信息. 正式开始前,编译环境gcc g++ 开发库之类的需要提前装好,这里默认你已经装好. ububtu平台编译环境可以使用以下指令 apt-get install build-essential apt-get install libtool centos平台编译环境使用如下指令 安装make: yum -y install gcc automake autoconf libtool make 安装g++:

Linux下pure-ftpd编译安装配置步骤详解

mkdir -p /home/src cd /home/src ## 下载源码包 wget -c http://lnmp.xiaobai.com/1.0/src/pure-ftpd-1.0.29.tar.gz ## 解压 tar zxvf pure-ftpd-1.0.29.tar.gz ## 进入目录 cd pure-ftpd-1.0.29 ## 编译安装 ./configure –prefix=/usr/local/webserver/pure-ftpd –with-everything –w

oracle11.2.0.4 GI单独安装tfa步骤详解

在11.2.0.4安装rac执行root.sh之时需要在root的环境变量中指定可以直接执行unzip命令(在非Linux,Win环境下root用户默认环境变量无unzip命令),如果忘记执行配置相应的PATH环境变量,将导致tfa不被安装,事后安装步骤 未安装tfa现状 --/etc/inittab中只有这一条和gi相关 h1:2:respawn:/etc/init.ohasd run >/dev/null 2>&1 </dev/null   --只启动了init.ohasd

OSX(YOSEMITE)上安装METASPLOIT步骤详解

Metasploit一款基于ruby的渗透测试框架,官方只提供Windows和Linux的安装包,要在osx上安装需要手动准备运行环境,下面介绍安装过程. 安装要求: 技能:会使用Terminal,了解命令sudo的作用,帐号具备管理员权限. 操作系统:我使用的OS X Yosemite(10.10.3). 网络:似乎rubygem和一些代码托管网站在大陆是被封锁的,所以你可能需要用到代理.   1.安装Xcode and Command Line Development Tools 打开App

centos6下awstats安装配置步骤详解

awstats功能 一:访问量,访问次数,页面浏览量,点击数,数据流量等 二:精确到每月.每日.每小时的数据 三:访问者国家 四:访问者IP 五:Robots/Spiders的统计 六:访客持续时间 七:对不同Files type 的统计信息 八:Pages-URL的统计 九:访客操作系统浏览器等信息 十:其它信息(搜索关键字等等) I. 下载源码 下载地址:http://www.awstats.org/#DOWNLOAD 老高推荐下载Last stable # Last stable vers

Centos7 安装docker-compose步骤详解

安装PIP sudo yum install python-pip.noarch #对安装好的pip进行一次升级 sudo pip install --upgrade pip 安装docker-compose pip install docker-compose 运行docker-compose 出现报错 pkg_resources.DistributionNotFound: backports.ssl-match-hostname>=3.5 使用pip 更新backports.ssl-matc