The SignalWire PHP SDK is designed to be run from the command line. Agent scripts are standard PHP files that create an agent and call run() to start the HTTP server.
php examples/simple_agent.phpOutput:
Starting the agent. Press Ctrl+C to stop.
Agent 'simple' is available at:
URL: http://localhost:3000/simple
Basic Auth: signalwire:a1b2c3d4e5f6...
Set credentials before running:
export SIGNALWIRE_PROJECT_ID=your-project-id
export SIGNALWIRE_API_TOKEN=your-api-token
export SIGNALWIRE_SPACE=example.signalwire.comuse SignalWire\Agent\AgentBase;
$agent = new AgentBase(
name: 'my-agent',
route: '/agent',
host: '0.0.0.0',
port: 8080,
);Or via environment:
export PORT=8080
php agent.phpexport SWML_BASIC_AUTH_USER=admin
export SWML_BASIC_AUTH_PASSWORD=mysecretpassword
php agent.phpUse AgentServer to host multiple agents:
php examples/multi_agent_server.phpOutput:
Starting Multi-Agent AI Server
Available agents:
- http://localhost:3000/healthcare - Healthcare AI (HIPAA compliant)
- http://localhost:3000/finance - Financial Services AI
- http://localhost:3000/retail - Retail Customer Service AI
curl -u signalwire:password http://localhost:3000/agentcurl -u signalwire:password 'http://localhost:3000/agent?customer_tier=vip&department=sales'curl -X POST -u signalwire:password \
-H 'Content-Type: application/json' \
-d '{"function":"get_weather","argument":{"location":"Austin"}}' \
http://localhost:3000/agent/swaigREST client scripts run once and exit:
export SIGNALWIRE_PROJECT_ID=your-project-id
export SIGNALWIRE_API_TOKEN=your-api-token
export SIGNALWIRE_SPACE=example.signalwire.com
php rest/examples/rest_manage_resources.phpRELAY scripts connect via WebSocket and run continuously:
export SIGNALWIRE_PROJECT_ID=your-project-id
export SIGNALWIRE_API_TOKEN=your-api-token
export SIGNALWIRE_SPACE=example.signalwire.com
php relay/examples/relay_answer_and_welcome.phpOutput:
Waiting for inbound calls on context 'default' ...
FROM php:8.2-cli
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader
COPY . .
EXPOSE 3000
CMD ["php", "agent.php"]docker build -t my-agent .
docker run -p 3000:3000 \
-e SIGNALWIRE_PROJECT_ID \
-e SIGNALWIRE_API_TOKEN \
-e SIGNALWIRE_SPACE \
my-agent{
"require": {
"signalwire/sdk": "^3.0"
}
}composer installexport SIGNALWIRE_LOG_LEVEL=debug
php agent.php$agent->enableDebugEvents(true);
$agent->onDebugEvent(function ($event) {
file_put_contents('php://stderr', json_encode($event) . "\n");
});export SIGNALWIRE_LOG_LEVEL=debug
php relay/examples/relay_answer_and_welcome.phpThis logs all WebSocket frames and protocol messages.
For production, use a process manager:
[program:agent]
command=php /app/agent.php
autostart=true
autorestart=true
environment=SIGNALWIRE_PROJECT_ID="...",SIGNALWIRE_API_TOKEN="...",SIGNALWIRE_SPACE="..."
stdout_logfile=/var/log/agent.log[Unit]
Description=SignalWire Agent
After=network.target
[Service]
Type=simple
User=www-data
ExecStart=/usr/bin/php /app/agent.php
EnvironmentFile=/etc/signalwire/agent.env
Restart=always
[Install]
WantedBy=multi-user.target