> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Concurrency

> 说明在 Laravel Copilot SDK 的 stdio / TCP 模式下，使用 Laravel Concurrency 进行并发执行的实践要点。

## 使用 Laravel Concurrency 进行并发执行

## stdio 模式的情况

虽然每一次都启动进程有些浪费，但只能用这种写法运行。由于 Concurrency 内部在做复杂的序列化，因此不返回 SessionEvent 类，而只返回 `content()` 的字符串。

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Illuminate\Support\Facades\Concurrency;

$prompt = 'Tell me something about Copilot.';

[$gpt5_response, $sonnet_response] = Concurrency::run([
    fn () => Copilot::run($prompt, config: ['model' => 'gpt-5.2'])->content(),
    fn () => Copilot::run($prompt, config: ['model' => 'claude-sonnet-4.5'])->content(),
]);

echo 'GPT-5 Response: '.$gpt5_response;
echo 'Claude Sonnet Response: '.$sonnet_response;
```

## TCP 模式的情况

因为没有进程启动，所以看起来会快一些，但实际上区别不大。

在 Process 驱动下，两者都经常在 60 秒时超时。在仅限 CLI 环境的 `fork` 驱动下，只有一边成功。异常并不会导致全部失败。当只有 `gpt-5` 失败时，把它换成 `gpt-5.2` 后两个都成功了。也许仅仅是模型响应时间的问题。

Concurrency 作为功能是存在的，但是否实用尚不清楚。耗时的处理基本上还是使用队列。

<Info>
  最新信息请参考 [GitHub 仓库](https://github.com/invokable/laravel-copilot-sdk)。
</Info>


## Related topics

- [并发处理](/zh/concurrency.md)
- [Laravel 11 升级到 12 指南](/zh/blog/upgrade-11-to-12.md)
- [2026 年 4 月 Laravel 更新](/zh/blog/changelog/202604.md)
- [引擎 API 集成应用开发指南 - VOICEVOX for Laravel](/zh/packages/laravel-voicevox/app-guide.md)
