> ## 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 driver 中兩者常於 60 秒逾時。專用於 CLI 環境的 `fork` driver 中僅有一邊成功，並不會以例外導致全部失敗。當時只有 `gpt-5` 失敗，改為 `gpt-5.2` 後兩者都成功。可能只是模型回應時間的問題。

Concurrency 功能雖然存在，但實用性目前不明。花時間的處理基本上仍應使用佇列。

<Info>
  最新資訊請參考 [GitHub 儲存庫](https://github.com/invokable/laravel-copilot-sdk)。
</Info>


## Related topics

- [並行處理](/zh-TW/concurrency.md)
- [從 Laravel 11 升級到 12 指南](/zh-TW/blog/upgrade-11-to-12.md)
- [2026 年 4 月 Laravel 更新](/zh-TW/blog/changelog/202604.md)
- [引擎 API 整合應用開發指南 - VOICEVOX for Laravel](/zh-TW/packages/laravel-voicevox/app-guide.md)
