TCP mode
Normally the SDK starts a new Copilot CLI process for every request (stdio mode). TCP mode lets you connect to a Copilot CLI server that’s already running.Advantages of TCP mode
- Better performance: no process-start overhead.
- Resource sharing: multiple Laravel processes can share the same CLI server.
- Process management: the CLI can be managed as a background process by Laravel Forge / Laravel Cloud.
- Deploy-friendly: automatic restart at deploy time is supported.
How to use it
1. Start a Copilot CLI server
2. Set an environment variable
tcp://is optional.http://or no scheme also works.- You can specify just a port; the host defaults to
127.0.0.1. - Specifying just a host works only with
127.0.0.1andlocalhost. The port defaults to12345.
Config file
You can configure the TCP connection inconfig/copilot.php.
COPILOT_URL (cli_url) and COPILOT_CLI_PATH are set, TCP mode takes precedence.
Switching modes at runtime
Normally the config file selects TCP or stdio mode automatically. You can also switch modes explicitly in code.Running on Laravel Forge / Laravel Cloud
Laravel Forge
-
Create a daemon: create a daemon from the Forge admin UI.
-
Set the environment variable: add
COPILOT_URLto.env. - Restart on deploy: restart the daemon from your deploy script.
Laravel Cloud
You can run it as a background process using Laravel Cloud’s worker feature. See Using it on Laravel Cloud for details.Notes
Security
Reconnection
There is no automatic reconnect in the current version. If the connection drops, an exception is thrown.Checking the current mode
You can check which mode the client is in from your code.Troubleshooting
Cannot connect
- Check whether the Copilot CLI server is running.
- Verify the port.
- Check firewall settings.
Timeout errors
Increase thetimeout value in config/copilot.php.
For the latest updates, see the GitHub repository.