首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
异步任务报错Uncaught ArgumentCountError: Too few arguments to function {closure}(), 2 passed and exactly 4 expected
1. 在提交问答前请尽可能回答以下问题: 2. 请详细描述问题的产生过程,贴出相关的代码,最好能提供一份可稳定重现的简单脚本代码。 ```php <?php require "proxy.php"; $taskWorkingList = []; $proxy = new ProxyCenter(); $serv = new \Swoole\Server("0.0.0.0", 8000); $serv->set([ 'reactor_num' => 1, 'worker_num' => 1, 'task_worker_num' => 1, 'task_enable_coroutine' => 1 ]); // 监听连接事件 $serv->on("Connect", function($serv, $fd) use ($proxy) { // 启动线程检测PHP服务节点 $proxy->detectPhpServNodes(); echo "Proxy started..." . PHP_EOL; }); // 监听接收消息事件 $serv->on("Receive", function($serv, $fd, $fromid, $data) use (&$taskWorkingList){ // 启动异步任务分发数据 $taskid = $serv->task($data); $taskWorkingList["t_{$taskid}"] = $taskid; echo "Dispatch AsyncTask: id={$taskid}" . PHP_EOL; }); // 监听异步任务事件 $serv->on("Task", function($serv, $task_id, $from_id, $data) { echo "New AsnycTask:id={$task_id}, data={$data}" . PHP_EOL; //返回任务执行的结果 $serv->finish("$data -> OK"); }); // 监听异步任务完成事件 $serv->on("Finish", function($serv, $taskid, $data) use (&$taskWorkingList) { // 修改任务标识符 unset($taskWorkingList["t_{$taskid}"]); echo "AsnycTask Finish: id={$taskid}" . PHP_EOL; }); // 监听连接关闭事件 $serv->on("Close", function($serv, $fd) use ($proxy, $taskWorkingList) { // 检测是否有异步任务正在进行 while (!empty($taskWorkingList)); // 断开与PHP服务节点间的连接 $proxy->disconnPhpServNodes(); echo "Proxy closed..." . PHP_EOL; }); $serv->start(); ``` 3. 期望的结果是什么? 不报错,输出异步任务函数中的信息 4. 实际运行的结果是什么? Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 2 passed and exactly 4 expected in /home/haitao/dev/scctest/proxy/server.php:32 5. 你的版本? 贴出 `php --ri swoole` 所打印的内容 Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.17 Built => Apr 3 2020 11:59:43 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled pcre => enabled zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 6. 你使用的机器系统环境是什么(包括内核、PHP、gcc编译器版本信息)?可以使用`uname -a`, `php -v`, `gcc -v` 命令打印 Linux iZbp15d84aus1psbd3lqk2Z 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux PHP 7.4.4 (cli) (built: Apr 3 2020 11:44:28) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
发布于4年前 · 0 次浏览 · 来自
提问
鸿鹄凌云之志
1. 在提交问答前请尽可能回答以下问题: 2. 请详细描述问题的产生过程,贴出相关的代码,最好能提供一份可稳定重现的简单脚本代码。 ```php <?php require "proxy.php"; $taskWorkingList = []; $proxy = new ProxyCenter(); $serv = new \Swoole\Server("0.0.0.0", 8000); $serv->set([ 'reactor_num' => 1, 'worker_num' => 1, 'task_worker_num' => 1, 'task_enable_coroutine' => 1 ]); // 监听连接事件 $serv->on("Connect", function($serv, $fd) use ($proxy) { // 启动线程检测PHP服务节点 $proxy->detectPhpServNodes(); echo "Proxy started..." . PHP_EOL; }); // 监听接收消息事件 $serv->on("Receive", function($serv, $fd, $fromid, $data) use (&$taskWorkingList){ // 启动异步任务分发数据 $taskid = $serv->task($data); $taskWorkingList["t_{$taskid}"] = $taskid; echo "Dispatch AsyncTask: id={$taskid}" . PHP_EOL; }); // 监听异步任务事件 $serv->on("Task", function($serv, $task_id, $from_id, $data) { echo "New AsnycTask:id={$task_id}, data={$data}" . PHP_EOL; //返回任务执行的结果 $serv->finish("$data -> OK"); }); // 监听异步任务完成事件 $serv->on("Finish", function($serv, $taskid, $data) use (&$taskWorkingList) { // 修改任务标识符 unset($taskWorkingList["t_{$taskid}"]); echo "AsnycTask Finish: id={$taskid}" . PHP_EOL; }); // 监听连接关闭事件 $serv->on("Close", function($serv, $fd) use ($proxy, $taskWorkingList) { // 检测是否有异步任务正在进行 while (!empty($taskWorkingList)); // 断开与PHP服务节点间的连接 $proxy->disconnPhpServNodes(); echo "Proxy closed..." . PHP_EOL; }); $serv->start(); ``` 3. 期望的结果是什么? 不报错,输出异步任务函数中的信息 4. 实际运行的结果是什么? Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 2 passed and exactly 4 expected in /home/haitao/dev/scctest/proxy/server.php:32 5. 你的版本? 贴出 `php --ri swoole` 所打印的内容 Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.17 Built => Apr 3 2020 11:59:43 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled pcre => enabled zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 6. 你使用的机器系统环境是什么(包括内核、PHP、gcc编译器版本信息)?可以使用`uname -a`, `php -v`, `gcc -v` 命令打印 Linux iZbp15d84aus1psbd3lqk2Z 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux PHP 7.4.4 (cli) (built: Apr 3 2020 11:44:28) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
2020-04-08
鲁飞
请重新修改代码排版后提问,使用 **```** 将你的代码包起来。 ```php // 你的php代码 ```
赞
0
回复
微信公众号
热门内容
暂无回复的问答
- CodeGalaxy K3s 轻量集群节点之间如何实现负载均衡
- 关于openssl CURL WARNING swSSL_connect: SSL_connect(fd=69) failed. Error: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small[1|394]
- 多个模型如何进行事务异常回退?
- websocket开启wss报错
- 协程tcp服务器如何使用多进程?recv()方法接收信息,打印出来的pid一直是同一个。没用使用到多进程啊。