在PHP 7下安装Swoole与Yar,Yaf的方法教程

yipeiwu_com6年前PHP代码库

本文开发坏境:

  • CentOS 7
  • PHP 7.0.16

安装PECL

//php版本 > 7
$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar
//php版本 < 7
$ yum install php-pear
//否则会报错PHP Parse error: syntax error, unexpected //'new' (T_NEW) in /usr/share/pear/PEAR/Frontend.php on //line 91

安装swoole

$ sudo pecl install swoole
//报错如下
//Warning: Invalid argument supplied for foreach() in //Command.php on line 249
vi `which pecl`
//找到最后一行
exec $PHP -C -n -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@"
去掉 -n 标示
//报错如下
//running: phpize
//Can't find PHP headers in /usr/include/php
//安装 php-devel
sudo yum install php70w-devel
成功!
//Build process completed successfully
//Installing '/usr/lib64/php/modules/swoole.so'
//install ok: channel://pecl.php.net/swoole-1.9.8

配置 php.ini

$ php -i | grep php.ini
//修改或者添加
 extension=swoole.so

安装 Yar和Yaf

$ sudo ./pecl install msgpack
//pecl/yar requires PHP (version >= 5.2.0, version <= 5.6.99), installed version is 7.0.16
//注意PHP7,要使用yar-2.0.2
$ sudo ./pecl install yar-2.0.2 //注意yar-2.0.2版本
//添加,json.so 要放到前面。否则会报
//PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/yar.so' - /usr/lib64/php/modules/yar.so: undefined symbol: php_json_decode_ex in Unknown on line 0
extension=json.so //放前面
extension=msgpack.so
extension=yar.so
//重启php服务
sudo systemctl restart php-fpm.service
//其他报错
//perl: warning: Setting locale failed.
//perl: warning: Please check that your locale //settings:
// LANGUAGE = (unset),
// LC_ALL = (unset),
 // LANG = "en_US.UTF-8"
 
$ localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
//其他报错
//checking for cURL in default path... not found
//configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
$ sudo yum -y install curl-devel
//安装Yaf
$ sudo ./pecl install yaf
//更新php.ini
extension=yaf.so
//重启服务
$ sudo systemctl restart php-fpm.service
//安装脚手架
$ git clone http://pecl.php.net/package/yaf
$ cd php-yaf/tools/cg
$ php yaf-cg app
//配置 项目目录指向 app/index.php
//访问配置host

nginx 配置

server {
 listen ****;
 server_name domain.com;
 root document_root;
 index index.php index.html index.htm;
 
 if (!-e $request_filename) {
 rewrite ^/(.*) /index.php/$1 last;
 }
}

Enjoy it!

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对【宜配屋www.yipeiwu.com】的支持。

相关文章

在WordPress中使用wp_count_posts函数来统计文章数量

做一个全站统计是不是很酷?长久的博客越来越少,何不给自己的一个统计,看看自己在这个博客上努力了多少,不但给自己也给游客,wp_count_posts是在 WordPress 中用来统计文...

PHP打开和关闭文件操作函数总结

PHP打开和关闭文件操作函数总结

在处理文件内容之前,通常需要建立与文件资源的连接,即打开文件。同样,结束该资源的操作后,应当关闭连接资源。所谓打开文件,实际是建立文件的各种有关信息,并使文件指针指向该文件,就可以发起输...

php处理复杂xml数据示例

本文实例讲述了php处理复杂xml数据的方法。分享给大家供大家参考,具体如下: <?php $xml = <<< XML <?xml v...

php 字符串中是否包含指定字符串的多种方法

编写程序的时候,经常要处理字符串,最基本就是字符串的查找,在php检测字符串中是否包含指定字符串可以使用正则,如果你对正则不了解,那么有几个函数可以为您提供方便。 strpos() 函数...

PHP Zip解压 文件在线解压缩的函数代码

复制代码 代码如下: /********************** *@file - path to zip file *@destination - destination dire...