大家好,又见面了,我是全栈君。
代码语言:javascript复制[root@vagrant-centos7 server]# php read.php
PHP Fatal error: Uncaught Error: Call to undefined function swoole_async_readfile() in /home/wwwroot/default/newproject/swoolechat/swoole-src/examples/server/read.php:13
Stack trace:
#0 {main}
thrown in /home/wwwroot/default/newproject/swoolechat/swoole-src/examples/server/read.php on line 13
Fatal error: Uncaught Error: Call to undefined function swoole_async_readfile() in /home/wwwroot/default/newproject/swoolechat/swoole-src/examples/server/read.php:13
Stack trace:
#0 {main}
thrown in /home/wwwroot/default/newproject/swoolechat/swoole-src/examples/server/read.php on line 13
解答:
https://github.com/swoole/swoole-src/issues/2439
https://segmentfault.com/q/1010000018413486?sort=created
https://wiki.swoole.com/wiki/page/p-async.html
4.3的版本移除所有异步模块, 分离异步扩展到 async-ext 移除的异步模块如下:
从4.3
版本开始需要额外安装swoole-async
扩展才能使用异步模块
不要直接拉取 master 代码进行编译,请使用和 swoole
版本对应的 ext-async
的 release
版本https://github.com/swoole/ext-async/releases
Async系列函数
MySQL
Redis
HttpClient
MemoryPool
MsgQueue
RingQueue
如何才能解决这个问题呢?
使用协程替换,或者安装async-ext扩展https://github.com/swoole/ext-async
因为我的swoole版本为Version => 4.5.0-alpha 而最新的async-ext扩展版本为v4.4.14, 所以只能卸载swoole重新编译.
卸载参考:
https://blog.csdn.net/zhangzeshan/article/details/102568239
https://blog.csdn.net/lxw1844912514/article/details/103915055
安装好后:
解决问题:
read.php文件:
代码语言:javascript复制<?php
/**
* 异步读取文件
*User: lxw
*Date: 2020-01-20
*/
swoole_async_readfile(__DIR__ . '/1.txt',function ($filename, $fileContent){
echo "filename:".$filename.PHP_EOL;
echo "fileContent:".$fileContent.PHP_EOL;
echo '内部start:'.time().PHP_EOL;
});
echo '外部start:'.time().PHP_EOL;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/111936.html原文链接:https://javaforall.cn