Serverless Functions
Also Known As
Lambda
Cloud Functions
FaaS
function as a service
Bref
TL;DR
Event-triggered, stateless functions managed by a cloud provider — you deploy code, the provider handles servers, scaling, and availability.
Explanation
Serverless (Lambda, Cloud Functions, Azure Functions) runs code in response to events (HTTP request, queue message, cron schedule) without provisioning or managing servers. Billing is per invocation and execution time — idle costs nothing. Cold starts add latency when a function hasn't run recently. Functions must be stateless — any persistent state lives in a database or cache. PHP is supported via custom runtimes (Bref) on AWS Lambda.
Diagram
flowchart LR
REQ[HTTP Request] --> GW[API Gateway]
GW -->|cold start or warm| FN[Function Instance<br/>PHP via Bref]
FN --> EXEC[Execute handler<br/>100ms-3s]
FN --> DB[(Database)]
FN --> S3[(S3)]
subgraph Scaling
GW -->|concurrent requests| FN1[Instance 1]
GW -->|concurrent requests| FN2[Instance 2]
GW -->|concurrent requests| FN3[Instance N - auto]
end
INFO[Pay per invocation<br/>Zero idle cost<br/>Cold start: 200ms-2s]
style FN fill:#238636,color:#fff
style INFO fill:#1f6feb,color:#fff
Common Misconception
✗ Serverless means no servers — the servers exist, you just don't manage them; 'serverless' means no server management, not no servers.
Why It Matters
Serverless eliminates server management, scales to zero, and costs nothing at idle — ideal for event-driven workloads, but cold starts and statelessness require architectural adjustments.
Common Mistakes
- Storing state in the function's memory or filesystem — functions are ephemeral; use Redis or a database.
- Ignoring cold start latency — functions not invoked recently take 200-2000ms to initialise.
- Monolithic serverless functions — small, single-purpose functions scale and deploy independently.
- Not setting memory/timeout limits — unlimited execution time runs up costs on stuck functions.
Code Examples
✗ Vulnerable
// Stateful serverless — state lost between invocations:
$counter = 0; // Top-level 'global' variable
function handler($event) {
global $counter;
$counter++; // Resets to 0 on every cold start — not persistent
return ['count' => $counter];
}
✓ Fixed
// Stateless — state in Redis:
function handler($event) {
$redis = new Redis();
$redis->connect(getenv('REDIS_HOST'));
$count = $redis->incr('invocation_count');
return ['count' => $count]; // Persists across invocations
}
// Bref (PHP on Lambda): composer require bref/bref
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
26
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Perplexity 7
Amazonbot 6
Google 4
Ahrefs 3
SEMrush 2
Unknown AI 1
Also referenced
How they use it
crawler 20
crawler_json 3
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: High
⚡ Quick Fix
Use Bref (bref.sh) to deploy PHP on AWS Lambda — it handles the Lambda runtime; keep functions small, stateless, and under 50MB; use SQS triggers for queue processing
📦 Applies To
PHP 7.4+
web
cli
laravel
symfony
🔗 Prerequisites
🔍 Detection Hints
PHP app with variable traffic spikes paying for idle EC2; suitable for Lambda but running on always-on server
Auto-detectable:
✗ No
bref
serverless
aws-sam
terraform
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: Medium
✗ Manual fix
Fix: High
Context: File
Tests: Update