


Share the tutorial on how to install Swoole, Yar, and Yaf under PHP 7
周末闲来无事,玩玩swoole,所以下面这篇文章主要给大家介绍了在PHP 7下安装Swoole与Yar,Yaf的方法教程,文中介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
本文开发坏境:
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!
The above is the detailed content of Share the tutorial on how to install Swoole, Yar, and Yaf under PHP 7. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Swoole coroutines in Laravel can process a large number of requests concurrently. The advantages include: Concurrent processing: allows multiple requests to be processed at the same time. High performance: Based on the Linux epoll event mechanism, it processes requests efficiently. Low resource consumption: requires fewer server resources. Easy to integrate: Seamless integration with Laravel framework, simple to use.

Swoole Process allows users to switch. The specific steps are: create a process; set the process user; start the process.

Swoole and Workerman are both high-performance PHP server frameworks. Known for its asynchronous processing, excellent performance, and scalability, Swoole is suitable for projects that need to handle a large number of concurrent requests and high throughput. Workerman offers the flexibility of both asynchronous and synchronous modes, with an intuitive API that is better suited for ease of use and projects that handle lower concurrency volumes.

To restart the Swoole service, follow these steps: Check the service status and get the PID. Use "kill -15 PID" to stop the service. Restart the service using the same command that was used to start the service.

Performance comparison: Throughput: Swoole has higher throughput thanks to its coroutine mechanism. Latency: Swoole's coroutine context switching has lower overhead and smaller latency. Memory consumption: Swoole's coroutines occupy less memory. Ease of use: Swoole provides an easier-to-use concurrent programming API.

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

Swoole in action: How to use coroutines for concurrent task processing Introduction In daily development, we often encounter situations where we need to handle multiple tasks at the same time. The traditional processing method is to use multi-threads or multi-processes to achieve concurrent processing, but this method has certain problems in performance and resource consumption. As a scripting language, PHP usually cannot directly use multi-threading or multi-process methods to handle tasks. However, with the help of the Swoole coroutine library, we can use coroutines to achieve high-performance concurrent task processing. This article will introduce

Swoole coroutine is a lightweight concurrency library that allows developers to write concurrent programs. The Swoole coroutine scheduling mechanism is based on the coroutine mode and event loop, using the coroutine stack to manage coroutine execution, and suspend them after the coroutine gives up control. The event loop handles IO and timer events. When the coroutine gives up control, it is suspended and returns to the event loop. When an event occurs, Swoole switches from the event loop to the pending coroutine, completing the switch by saving and loading the coroutine state. Coroutine scheduling uses a priority mechanism and supports suspend, sleep, and resume operations to flexibly control coroutine execution.
