简体   繁体   中英

Using Amphp with a framework such as Magento

I am trying to use Amphp Parallel functions with the Magento framework in a custom module.

try {
    $response = wait(parallelMap($items, function ($item) use ($arg1){
        $this->getCustomItems( $item, $arg1);
    }));

} catch (MultiReasonException $exception) {
    foreach ($exception->getReasons() as $reason) {
        var_dump($reason->getMessage());
    }
}

The issue i am having when running the above code is

Uncaught RuntimeException in worker with message "ObjectManager isn't initialized" and code "0"; use Amp\Parallel\Worker\TaskFailureException::getOriginalTrace() for the stack trace in the worker

The Magento framework is autoloaded using composer. So i have no clue as to why it can not initialize the object manager.

Magento 的依赖是通过 autoload 自动加载的,但是当它没有被 Magento 内核初始化时是没有用的,你需要创建一个单独的 Magento API,并通过你的 vendor 中编写的回调方法(使用 CURL 请求)请求该 API /autloload.php,这是您可以使用 amphp 的方式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM