linux系统lampp运行环境使用pthreads PHP扩展出错

kuangkuang1 发布于 2015/12/25 16:25
阅读 2K+
收藏 1

    想问下在linux服务器上,lampp运行环境,想使用php多线程,需要使用pthreads PHP扩展,直接安装pthreads-master,提示需要开启-enable-maintainer-zts,需要php重新编译

./configure --prefix=/opt/lampp/include/php --with-config-file-path=/opt/lampp/include/php/etc --with-mysql=/usr/include/mysql --with-mysqli=/usr/bin/mysql_config --with-inconv-dir --with-freetype-dir=/opt/lampp/bin --with-jpeg-dir=/opt/lampp/bin --with-png-dir=/opt/lampp/bin --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=/opt/lampp/bin --with-gd --enable-ge-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts

出现错误:configure: error: Cannot find MySQL header files under /usr/include/mysql.
Note that the MySQL client library is not bundled anymore!

用find / -name mysql.h

有两个/usr/include/mysql/mysql.h
/opt/lampp/include/mysql.h

这两个都试了下,都不行cannot find mysql,求解决~

另外想问下在lampp运行环境下,开启pthreads PHP扩展有没有什么其他的方法~

加载中
0
mickelfeng
mickelfeng
./configure --prefix=/opt/lampp/include/php --with-config-file-path=/opt/lampp/include/php/etc  --with-inconv-dir --with-freetype-dir=/opt/lampp/bin --with-jpeg-dir=/opt/lampp/bin --with-png-dir=/opt/lampp/bin --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=/opt/lampp/bin --with-gd --enable-ge-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache  --enable-maintainer-zts


--with-mysql=/usr/include/mysql 
--with-mysqli=/usr/bin/mysql_config


给你换成了以下参数,你那参数需要先安装mysql,环境中要由mysql开发库才行。

--enable-mysqlnd  
--with-mysql=mysqlnd 
--with-mysqli=mysqlnd 
--enable-pdo 
--with-pdo-mysql

另外开启pthreads PHP扩展,扩展也依赖pthreads库,linux一般有

k
kuangkuang1
回复 @mickelfeng : 安装pthreads-master路径,不过make的时候还有一个错误,就是 ./classes/pool.h:330: error: too few arguments to function 'zend_hash_apply' make: *** [php_pthreads.lo] Error 1 帮我再看下~终于快弄好了~我这小笨脑袋~谢谢~
mickelfeng
mickelfeng
你编译的时候可能没加这个参数 ,还有就是看是不是你编译的那个版本
k
kuangkuang1
回复 @mickelfeng : 再问下哈~为嘛我php重新编译后,打开phpinfo,找不到enable-maintainer-zts,是什么情况哈~是缺少了什么吗?求解答
k
kuangkuang1
echo "/usr/local/lib" >> /etc/ld.so.conf.d/local.conf /sbin/ldconfig 加入 /usr/local/lib 后ldconfig 这样再配置就没有错误了~谢谢哈~
mickelfeng
mickelfeng
--enable-opcache=no 替换成这样
下一页
0
k
kuangkuang1

把mysql的改成这样 --with-mysql=/opt/lampp/include --with-mysqli=/opt/lampp/bin/mysql_config

还是出现can't find mysql

来个大神帮我解决下哈~谢谢了~一直都是在win下编程的,现在给我个liunx服务器代码放上去需要

pthreads PHP扩展,求解决啊 @Tuesday@梦想岛@mickelfeng 来帮忙看下哈~


0
k
kuangkuang1
@微默 @梁上有木 来帮忙看下哈~谢谢~无论怎么弄都是can't find mysql
0
eechen
eechen
可以看下我的编译参数:
http://my.oschina.net/eechen/blog/411534
安装编译PHP依赖的开发工具和库:
sudo apt-get install \
build-essential \
autoconf \
libtool \
re2c \
libxml2-dev \
openssl \
libcurl4-openssl-dev \
libbz2-dev \
libjpeg-dev \
libpng12-dev \
libfreetype6-dev \
libldap2-dev \
libmcrypt-dev \
libmysqlclient-dev \
libxslt1-dev \
libxt-dev \
libpcre3-dev \
libxpm-dev \
libt1-dev \
libgmp-dev \
libpspell-dev \
librecode-dev \
libreadline6-dev

configure_php.sh
#!/bin/bash
./configure \
--prefix=/png/php/5.4 \
--enable-maintainer-zts \
--enable-fpm \
--enable-pdo \
--enable-sockets \
--enable-exif \
--enable-soap \
--enable-ftp \
--enable-wddx \
--enable-pcntl \
--enable-soap \
--enable-bcmath \
--enable-mbstring \
--enable-dba \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-zip \
--enable-calendar \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-mysql \
--with-mysqli \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-iconv \
--with-gmp \
--with-pspell \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-mcrypt \
--with-xsl \
--with-curl \
--with-pcre-regex \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-zlib-dir=/usr \
--with-xpm-dir=/usr \
--with-freetype-dir=/usr \
--with-gettext=/usr \
--with-zlib=/usr \
--with-bz2=/usr \
--with-recode=/usr \
--with-ldap \
--with-pear \
--with-readline

安装pthreads多线程扩展:
/png/php/5.4/bin/pecl install pthreads
k
kuangkuang1
想问你下哈~我重新编译php后在phpinfo()下面查看的,Thread Safety是disabled,这个是不是要变成enabled才可以啊~现在 pthreads make一直出错~求解答啊~这个弄了几天了,还不好~求解答下哈~谢谢~我原本的lampp里面的php是5.5.30,我重新编译的也是5.5.30~
k
kuangkuang1
我这边公司电脑屏蔽了一些网站,打不开你给的网址,我回去看下哈~谢谢啦~刚开始在linux下写东西,以后希望你能多多帮助我哈~十分感谢~
0
k
kuangkuang1

引用来自“mickelfeng”的评论

./configure --prefix=/opt/lampp/include/php --with-config-file-path=/opt/lampp/include/php/etc  --with-inconv-dir --with-freetype-dir=/opt/lampp/bin --with-jpeg-dir=/opt/lampp/bin --with-png-dir=/opt/lampp/bin --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=/opt/lampp/bin --with-gd --enable-ge-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache  --enable-maintainer-zts


--with-mysql=/usr/include/mysql 
--with-mysqli=/usr/bin/mysql_config


给你换成了以下参数,你那参数需要先安装mysql,环境中要由mysql开发库才行。

--enable-mysqlnd  
--with-mysql=mysqlnd 
--with-mysqli=mysqlnd 
--enable-pdo 
--with-pdo-mysql

另外开启pthreads PHP扩展,扩展也依赖pthreads库,linux一般有

安装pthreads-master路径错了,现改成了
cd pthreads-master
/opt/lampp/include/php/bin/phpize
./configure --with-php-config =/opt/lampp/include/php/bin/php-config
不过现在还有一个错误,就是./classes/pool.h:330: error: too few arguments to function \u2018zend_hash_apply\u2019
make: *** [php_pthreads.lo] Error 1

我再看看~终于快弄好了~我这小笨脑袋~

k
kuangkuang1
回复 @mickelfeng : :https://github.com/krakjoe/pthreads和http://pecl.php.net/package/pthreads
mickelfeng
mickelfeng
回复 @kuangkuang1 : qq: 446838006
k
kuangkuang1
要不你给我个qq号或者微信号,我加下你~可以给你截图看下~不过我手机信号也有点屏蔽~估计会比较慢~谢谢哈~
k
kuangkuang1
回复 @mickelfeng : 还是不行啊~呜呜~还是 make: *** [php_pthreads.lo] Error 1 这个错误~并且make 有好多的error~ 我用了几个的 pthreads包了 是不是我要在php.ini里添加神马东西~我用的php是5.5.30
mickelfeng
mickelfeng
回复 @kuangkuang1 : 跟这个没有关系。这个是线程安全。disabled也可以用。
下一页
0
k
kuangkuang1

引用来自“mickelfeng”的评论

./configure --prefix=/opt/lampp/include/php --with-config-file-path=/opt/lampp/include/php/etc  --with-inconv-dir --with-freetype-dir=/opt/lampp/bin --with-jpeg-dir=/opt/lampp/bin --with-png-dir=/opt/lampp/bin --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=/opt/lampp/bin --with-gd --enable-ge-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache  --enable-maintainer-zts


--with-mysql=/usr/include/mysql 
--with-mysqli=/usr/bin/mysql_config


给你换成了以下参数,你那参数需要先安装mysql,环境中要由mysql开发库才行。

--enable-mysqlnd  
--with-mysql=mysqlnd 
--with-mysqli=mysqlnd 
--enable-pdo 
--with-pdo-mysql

另外开启pthreads PHP扩展,扩展也依赖pthreads库,linux一般有

引用来自“kuangkuang1”的评论

安装pthreads-master路径错了,现改成了
cd pthreads-master
/opt/lampp/include/php/bin/phpize
./configure --with-php-config =/opt/lampp/include/php/bin/php-config
不过现在还有一个错误,就是./classes/pool.h:330: error: too few arguments to function \u2018zend_hash_apply\u2019
make: *** [php_pthreads.lo] Error 1

我再看看~终于快弄好了~我这小笨脑袋~

回复 @mickelfeng : 呜呜~现在还是用不了pthreads,想再问下哈~phpinfo下
Configuration File (php.ini) Path /opt/lampp/etc
Loaded Configuration File /opt/lampp/etc/php.ini

extension_dir /opt/lampp/include/php/lib/php/extensions/no-debug-zts-20121212/     /opt/lampp/include/php/lib/php/extensions/no-debug-zts-20121212/
这个目录也是对的~在/opt/lampp/etc/php.ini这个.ini文件里面改的extension_dir=/opt/lampp/include/php/lib/php/extensions/no-debug-zts-20121212/
extension="pthreads.so" 我真心的不知道我哪个地方还错了哈~求再指点下~感谢~

0
mickelfeng
mickelfeng
修改加载的php.ini ,extension_dir=扩展生成的目录,  extension=扩展名.so
k
kuangkuang1
Wrote PEAR system config file at: /opt/lampp/include/php/etc/pear.conf You may want to add: /opt/lampp/include/php/lib/php to your php.ini include_path /root/php-5.5.30/build/shtool install -c ext/...
k
kuangkuang1
想再问一下哈~我又重新编译了php,出现了下面的提示,是要做什么吗?
k
kuangkuang1
Fatal error: Class 'Thread' not found in /opt/lampp/htdocs/DPDC/Crawl/test_sn.class.php on line 3,还是报错,还是报错
k
kuangkuang1
修改的就是phpinfo里面的php.ini的目录所在的文件啊~就是不对~唉
0
k
kuangkuang1

引用来自“mickelfeng”的评论

./configure --prefix=/opt/lampp/include/php --with-config-file-path=/opt/lampp/include/php/etc  --with-inconv-dir --with-freetype-dir=/opt/lampp/bin --with-jpeg-dir=/opt/lampp/bin --with-png-dir=/opt/lampp/bin --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=/opt/lampp/bin --with-gd --enable-ge-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache  --enable-maintainer-zts


--with-mysql=/usr/include/mysql 
--with-mysqli=/usr/bin/mysql_config


给你换成了以下参数,你那参数需要先安装mysql,环境中要由mysql开发库才行。

--enable-mysqlnd  
--with-mysql=mysqlnd 
--with-mysqli=mysqlnd 
--enable-pdo 
--with-pdo-mysql

另外开启pthreads PHP扩展,扩展也依赖pthreads库,linux一般有

放假了几天,今天刚上班哈~@mickelfeng大师傅,我又重新编译了php,出现了下面的提示,是需要做什么吗?

Wrote PEAR system config file at: /opt/lampp/include/php/etc/pear.conf
You may want to add: /opt/lampp/include/php/lib/php to your php.ini include_path
/root/php-5.5.30/build/shtool install -c ext/phar/phar.phar /opt/lampp/include/php/bin
ln -s -f phar.phar /opt/lampp/include/php/bin/phar

0
mickelfeng
mickelfeng

你没安装成功。

PHPDIR/phpize

./configure --with-php-config=/PHPDIR/bin/php-config
make

make install

vi /PHPDIR/etc/php.ini


添加:
extension = "pthreads.so"

<?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.baidu.com/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";
?>

k
kuangkuang1
运行phpize提示这样的错误: cannot find config.m4. Make sure that you run '/usr/bin/phpize' in the top level source directory of the module 这个php重新编译的~好像一直是重新安装的失败啊~
0
k
kuangkuang1

引用来自“mickelfeng”的评论

你没安装成功。

PHPDIR/phpize

./configure --with-php-config=/PHPDIR/bin/php-config
make

make install

vi /PHPDIR/etc/php.ini


添加:
extension = "pthreads.so"

<?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.baidu.com/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";
?>

大师父,我又重新安装了一下:./configure --prefix=/opt/lampp/include/php --with-config-file-path=/opt/lampp/include/php/etc --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-inconv=/opt/lampp/lib --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-ge-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --with-apxs2=/opt/lampp/bin/apxs --enable-maintainer-zts

安装完成后,再cp php.ini-production /opt/lampp/include/php/etc/php.ini

php重新编译完成了~呼呼,终于弄好了~感谢哈~@mickelfeng

k
kuangkuang1
使用mysql的时候会出错~需要把新的php.ini里面的这三项:mysql.default_socket = pdo_mysql.default_socket= mysqli.default_socket = 都设置为 mysql.sock(或mysqld.sock)的具体路径~ 完美~终于解决啦~
返回顶部
顶部