php - 将 Amphp 与用户定义的函数并行使用时出错
问题描述
我正在尝试使用 Worker\enqueueCallable 调用用户定义的函数。
我已将该函数放在一个单独的文件中,并使用 composer 来自动加载它。
我得到了错误:
致命错误:未捕获的类型错误:传递给 Amp\Parallel\Worker\enqueueCallable() 的参数 1 必须是可调用的,给定字符串”
我的文件夹结构
Project Folder/
app/
funcs.php
caller.php
main.php
composer.json
在caller.php和funcs.php中都使用了命名空间应用程序
然后在 composer.json 中使用以下代码段并使用composer dumpautoload -o
{
"autoload": {
"psr-4": {
"app\\": "app/"
},
"files": [ "app/funcs.php" ]
},
"require": {
"amphp/parallel": "^1.3",
"amphp/parallel-functions": "^0.1.3"
}
}
从main.php我调用caller.php调用funcs.php中定义的函数
函数.php
namespace app;
function f1($param1){
#Do some stuff
}
调用者.php
namespace app;
use Amp\Parallel\Worker;
use Amp\Promise;
class cls
{
function __construct()
{
}
function Invoker()
{
// If I call the function, its working.
f1($param1);
// When I am using its not working.
$promises[] = Worker\enqueueCallable('f1', $param1);
}
}
主文件
require __DIR__ . '\vendor\autoload.php';
use app\cls;
$obj = new cls();
$obj->Invoker();
我正在使用 Windows-10、WAMP 服务器和 PHP 版本 7.3.5。
解决方案
推荐阅读
- javascript - React Native 性能缓慢
- linux - 如何在多个容器之间共享 CPU 配额?
- android - 如何在 RecyclerView 中获取特定位置视图?
- wordpress - 为什么当 gulp 在浏览器中打开网站时出现错误?
- python - python链表leetcode问题21合并两个有序列表
- google-sheets - 在 Google 表格中计算 24 小时以上的时间值总和
- r - `conn <- dbConnect()` 的问题,但正在执行一个干净的 `dbConnect()`
- powerbi - power BI 相对日期过滤器
- python - 财务回测程序上的 RuntimeWarning
- python - Python 没有检测到两个值相等并且一直返回 false