[英]"RuntimeException: a facade root has not been set"
I'm having an issue in a Laravel Zero project I'm working on.我在我正在处理的 Laravel 零项目中遇到问题。 I'm working on a command that handles direct file transfers between 2 disks—1 SFTP and another local.
我正在处理一个处理 2 个磁盘(1 个 SFTP 和另一个本地磁盘)之间的直接文件传输的命令。
I have configured both correctly and tested that I'm able to transfer files between them using the Storage
code below.我已经正确配置并测试了我能够使用下面的
Storage
代码在它们之间传输文件。 My issue pops up when I try to do this using the spatie/async
package to create a pool of concurrent transfers (or maybe just the way I'm trying to do it).当我尝试使用
spatie/async
package 创建并发传输池(或者可能只是我尝试这样做的方式)来执行此操作时,会出现我的问题。
$pool = Pool::create()
->concurrency($limit);
$progress = $this->output->createProgressBar($file_list);
if(!Storage::disk('local')->exists($local_folder_path)) {
Storage::disk('local')->makeDirectory($local_folder_path);
}
foreach($file_list as $filename => $remote_path) {
$pool->add(function() use ($remote_path, $filename, $local_folder_path) {
Storage::disk('local')
->writeStream(
"{$local_folder_path}/{$filename}",
Storage::disk('remote')->readStream($remote_path)
);
return $filename;
})->then(function($filename) use (&$progress) {
$this->info("{$filename} downloaded");
$progress->advance();
})->catch(function($exception) {
$this->error($exception);
});
}
$pool->wait();
$progress->finish();
By the way, the error, RuntimeException: a facade root has not been set
, is being printed to my console via the catch()
handler for the first item in the pool.顺便说一下,错误
RuntimeException: a facade root has not been set
正在通过池中第一项的catch()
处理程序打印到我的控制台。 I did discover that much.我确实发现了这么多。
I've searched for answers to this issue, but all of the articles and other SO/Stack Exchange postings I've come across didn't seem even similar to whatever's causing my issue.我已经搜索了这个问题的答案,但我遇到的所有文章和其他 SO/Stack Exchange 帖子似乎与导致我的问题的原因都不相似。
Thanks in advance for any help.在此先感谢您的帮助。
The problem is that your callback (child process) is running without any setup.问题是您的回调(子进程)在没有任何设置的情况下运行。
A Task is useful in situations where you need more setup work in the child process.
在您需要在子进程中进行更多设置工作的情况下,任务很有用。 Because a child process is always bootstrapped from nothing, chances are you'll want to initialise eg.
因为子进程总是从无到有,所以您很可能想要初始化,例如。 the dependency container before executing the task.
执行任务之前的依赖容器。
The facades are setup by the kernel that runs the \LaravelZero\Framework\Bootstrap\RegisterFacades::class
.外观由运行
\LaravelZero\Framework\Bootstrap\RegisterFacades::class
的 kernel 设置。
You can create an instance of the kernel and run the bootstrap method to have your facades setup properly.您可以创建 kernel 的实例并运行引导方法以正确设置外观。
$pool->add(function() use ($remote_path, $filename, $local_folder_path) {
$app = require __DIR__.'/../../bootstrap/app.php';
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
Storage::disk('local')
->writeStream(
"{$local_folder_path}/{$filename}",
Storage::disk('remote')->readStream($remote_path)
);
return $filename;
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.