php专区

 首页 > php专区 > PHP基础 > 环境 > php多线程安装pthreads步骤详解

php多线程安装pthreads步骤详解

分享到:
【字体:
导读:
          php多线程安装pthreads方法有一点复杂了,下面的安装步骤有一些多,希望能帮助到各位. PHP扩展下载:https://github.com/krakjoe/pthreads PHP手册文档:http://php.net/manual/zh/book.pthreads.php 安装脚本,代...

php多线程安装pthreads方法有一点复杂了,下面的安装步骤有一些多,希望能帮助到各位.

PHP扩展下载:https://github.com/krakjoe/pthreads

PHP手册文档:http://php.net/manual/zh/book.pthreads.php

安装脚本,代码如下:

  1. #!/bin/sh 
  2. cd /web/soft/php 
  3. if [ -d "pthreads-master" ];then 
  4. rm -rf pthreads-master 
  5. fi 
  6. unzip pthreads-master.zip 
  7. cd pthreads-master 
  8. /web/server/php/bin/phpize 
  9. ./configure --with-php-config=/web/server/php/bin/php-config 
  10. make 
  11. make install 
  12. rm -rf pthreads-master 
  13. PHPINI="/web/server/php/etc/php.ini" 
  14. sed -i '907a extension = "pthreads.so"' $PHPINI 
  15. #更新php-fpm配置 
  16. sed -i 's%;pid = run/php-fpm.pid%pid = run/php-fpm.pid%' /web/server/php/etc/php-fpm.conf 
  17. sed -i 's%;error_log = log/php-fpm.log%error_log = log/php-fpm.log%' /web/server/php/etc/php-fpm.conf 
  18. #杀死php-fpm进程 
  19. ps aux | grep "php" | grep -v "grep" | awk '{print $2}' | xargs -i kill -9 {} 
  20. #启动php-fpm 
  21. /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包安装此库:

  1. centos-5 32位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el5.rf.i386.rpm 
  2. centos-5 64位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el5.rf.x86_64.rpm 
  3. centos-6 32位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el6.rf.i686.rpm 
  4. centos-6 64位:http://pkgs.repoforge.org/re2c/re2c-0.13.5-1.el6.rf.x86_64.rpm 
  5. configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled 

原因:我在编译php的时候没有加入 --enable-maintainer-zts,这个必须要重新编译php,不能动态加载的.

于是我重新编译了php,在原来的编译参数基础上那个加入了 --enable-maintainer-zts ,重新编译安装php即可.

以下为一个示例,代码如下:

  1. class test_thread_run extends Thread 
  2. public $url
  3. public $data
  4. public function __construct($url
  5. $this->url = $url
  6. public function run() 
  7. if(($url = $this->url)) 
  8. $this->data = model_http_curl_get($url); 
  9. function model_thread_result_get($urls_array
  10. {//开源代码phpfensi.com 
  11. foreach ($urls_array as $key => $value
  12. $thread_array[$key] = new test_thread_run($value["url"]); 
  13. $thread_array[$key]->start(); 
  14. foreach ($thread_array as $thread_array_key => $thread_array_value
  15. while($thread_array[$thread_array_key]->isRunning()) 
  16. usleep(10); 
  17. if($thread_array[$thread_array_key]->join()) 
  18. $variable_data[$thread_array_key] = $thread_array[$thread_array_key]->data; 
  19. return $variable_data
  20. function model_http_curl_get($url,$userAgent=""
  21. $userAgent = $userAgent ? $userAgent : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)'
  22. $curl = curl_init(); 
  23. curl_setopt($curl, CURLOPT_URL, $url); 
  24. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
  25. curl_setopt($curl, CURLOPT_TIMEOUT, 5); 
  26. curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); 
  27. $result = curl_exec($curl); 
  28. curl_close($curl); 
  29. return $result
  30. for ($i=0; $i < 100; $i++) 
  31. $urls_array[] = array("name" => "baidu""url" => "http://www.111cn.net/ s?wd=".mt_rand(10000,20000)); 
  32. $t = microtime(true); 
  33. $result = model_thread_result_get($urls_array); 
  34. $e = microtime(true); 
  35. echo "多线程:".($e-$t)."\n"
  36. $t = microtime(true); 
  37. foreach ($urls_array as $key => $value
  38. $result_new[$key] = model_http_curl_get($value["url"]); 
  39. $e = microtime(true); 
  40. echo "For循环:".($e-$t)."\n"
  41. ?> 
 
 
分享到:
开启PHP exif扩展方法详解
PHP exif函数的功能我就不说了,下面我来给大家整理在php中PHP exif扩展打开方法吧,此教程只适用于windows系统下安装了php. 服务器配置说明: 1.在php.ini文件中找到;extension=php_exif.dll,去掉前面的分号. 2.在php.ini文件中找到;extension=php_mbstring.dll,去掉前面的分号,并将此行移动到extension=php_exif...
php如何安装mysqli扩展模块的方法
php安装mysqli扩展模块我们只需要简单的进入生成就可以了,这个模块好像默认在linux系统中是存在的只是没有安装吧,具体安装步骤如下. 在某些时候,比如安装statusNet时,会报错: Cannot find a database extension.You need at least one of mysqli,pgsql 这表明在php中没有mysqli或pgsql扩展,这里就描述一下mysq...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……