mac 安装swoole php,Mac安装swoole并解决安装错误 - Laravel学习网

一、Swoole安装

1、PHP版本条件

Swoole-1.x需要 PHP-5.3.10 或更高版本

Swoole-2.x需要 PHP-7.0.0 或更高版本

Swoole-4.x需要 PHP-7.1.0 或更高版本

1、源码安装

cd swoole-src && \

phpize && \

./configure && \

make && sudo make install

注意要查看查看结尾安装路径,然后要注意一下Warning: mkdir(): File exists in System.php提示不影响安装使用。

Build process completed successfully

Installing '/usr/local/Cellar/php@7.3/7.3.17_1/include/php/ext/swoole/config.h'

Installing '/usr/local/Cellar/php@7.3/7.3.17_1/pecl/20180731/swoole.so'

Warning: mkdir(): File exists in System.php on line 294

PHP Warning: mkdir(): File exists in /usr/local/Cellar/php@7.3/7.3.17_1/share/php@7.3/pear/System.php on line 294

Warning: mkdir(): File exists in /usr/local/Cellar/php@7.3/7.3.17_1/share/php@7.3/pear/System.php on line 294

ERROR: failed to mkdir /usr/local/Cellar/php@7.3/7.3.17_1/pecl/20180731

2、使用swoole安装

pecl install swoole

注意要查看查看结尾安装路径,然后要注意一下Warning: mkdir(): File exists in System.php提示不影响安装使用。

/bin/sh /private/var/www/swoole-src-4.5.0/libtool --mode=install cp ./swoole.la /private/var/www/swoole-src-4.5.0/modules

cp ./.libs/swoole.so /private/var/www/swoole-src-4.5.0/modules/swoole.so

cp ./.libs/swoole.lai /private/var/www/swoole-src-4.5.0/modules/swoole.la

----------------------------------------------------------------------

Libraries have been installed in:

/private/var/www/swoole-src-4.5.0/modules

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable

during execution

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

----------------------------------------------------------------------

Build complete.

Don't forget to run 'make test'.

Password:

mkdir: /usr/local/Cellar/php@7.3/7.3.17_1/pecl: File exists

mkdir: /usr/local/Cellar/php@7.3/7.3.17_1/pecl: No such file or directory

make: *** [install-modules] Error 1

3、PHP中引入配置文件

然后通过php -i | grep php.ini定位php.ini文件所在位置,并打开该配置文件,在文件末尾shift + G追加如下内容:

[swoole]

extension=/private/var/www/swoole-src-4.5.0/modules/swoole.so

最后重启一下php即可:

sudo service php7.3-fpm restart

执行php-m看到swoole代表已成功安装。

4、异常解决方案

如果引入失败出现PHP Warning: PHP Startup: Unable to load dynamic library '/ussr/lib/php/20180731/swoole.so'报错,则是swoole.so文件位置不对。可以前往/usr/lib/php/的时间文件下查找是否有swoole.so如:

/usr/lib/php/20180731/

最后记得重启php

二、快速上手

在test.php中写入如下代码。

// 表明服务器启动后监听本地 9051 端口

$server = new swoole_http_server('127.0.0.1', 9501);

// 服务器启动时返回响应

$server->on("start", function ($server) {

echo "Swoole http server is started at http://127.0.0.1:9501\n";

});

// 向服务器发送请求时返回响应

// 可以获取请求参数,也可以设置响应头和响应内容

$server->on("request", function ($request, $response) {

$response->header("Content-Type", "text/plain");

$response->end("Hello World\n");

});

// 启动 HTTP 服务器

$server->start();

执行php test.php即可。

2fe70103dbae8c6efaece43c91e0db7a.png

5cb64443c1af493d7bed36140028d99d.png

原创文章,转载请注明 :Mac安装swoole并解决安装错误 - Laravel学习网

原文出处: https://phpartisan.cn/news/135.html

问题交流群 :168117787

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值