← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Serverless Functions

Cloud PHP 7.4+ Intermediate
debt(d9/e7/b7/t7)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9), no automated tool flags 'this app would suit Lambda' — detection_hints.automated is no, and misuse (state in memory, cold starts) only surfaces in production traffic patterns.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7), migrating to Bref/Lambda requires reworking state handling, deployment, bootstrapping, and packaging across the whole app — not a single-file change.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7), applies_to web+cli contexts and the serverless model shapes every handler: statelessness, cold starts, packaging size, and timeout limits constrain how new features are written.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7), the misconception ('serverless means no servers') plus filesystem/memory state assumptions contradict how traditional PHP-FPM apps behave — devs reach for $_SESSION or local files and silently break.

About DEBT scoring →

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

Added 15 Mar 2026
Edited 22 Mar 2026
Views 52
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 1 ping S 2 pings S 1 ping M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 2 pings S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 7 Perplexity 7 Scrapy 6 Ahrefs 5 Google 5 SEMrush 4 Claude 2 ChatGPT 2 PetalBot 2 Unknown AI 1 Meta AI 1 Bing 1
crawler 37 crawler_json 6
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


✓ schema.org compliant