TCP vs UDP
debt(d9/e5/b3/t5)
Closest to 'silent in production until users hit it' (d9). The detection_hints explicitly state 'automated: no' and describe confusion patterns (e.g., using UDP for reliable data transfer without ACK/retry where data loss is silent, or misunderstanding QUIC). No tools in detection_hints.tools can catch these protocol choice errors; they manifest only at runtime as dropped packets, failed DNS queries, or mysterious data loss under real network conditions.
Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix is conceptual rather than a single-line swap. Correcting a wrong protocol choice in PHP socket code (e.g., switching from TCP to UDP for DNS, or adding ACK/retry logic for UDP-based reliable transfer) requires changes across socket initialization, error handling, and potentially application-layer retry logic. It's not a single-line patch but not a full architectural rework either.
Closest to 'localised tax' (b3). The applies_to scope is web and cli contexts, but the choice of TCP vs UDP is typically confined to specific socket-programming components (DNS resolver code, WebSocket setup, or real-time feature implementation) rather than permeating the entire codebase. Most PHP web app code never touches raw socket protocol selection.
Closest to 'notable trap' (t5). The misconception field documents the canonical trap: 'UDP is always faster than TCP' — a widely believed but conditionally false claim. Additionally, the common_mistakes list the silent data loss when using UDP without ACK/retry and the non-obvious fact that QUIC (HTTP/3) is UDP with reimplemented reliability. These are documented gotchas that intermediate developers commonly encounter but aren't catastrophically counterintuitive.
Also Known As
TL;DR
Explanation
TCP (Transmission Control Protocol): connection-oriented (three-way handshake), guaranteed delivery (retransmission on loss), ordered packets, congestion control. Use for: HTTP/HTTPS, database connections, email, file transfers. UDP (User Datagram Protocol): connectionless, fire-and-forget, no guaranteed delivery, no ordering. Use for: DNS, video streaming, online games, VoIP, QUIC/HTTP3. The trade-off: TCP's reliability costs latency; UDP's speed costs reliability. Applications that can handle loss (real-time audio) prefer UDP; applications that cannot (banking) require TCP.
Common Misconception
Why It Matters
Common Mistakes
- Using TCP for DNS queries — UDP is standard (less overhead for small queries).
- Using UDP for reliable data transfer without implementing your own ACK/retry — data loss is silent.
- Not understanding that QUIC is UDP with reliability — HTTP/3's UDP doesn't mean unreliable.
- PHP stream sockets default to TCP — explicitly specify udp:// for UDP socket programming.
Code Examples
// UDP for order confirmation — data can be silently lost:
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_sendto($socket, $orderConfirmation, strlen($orderConfirmation), 0,
'10.0.0.1', 9000);
// Fire and forget — confirmation may never arrive
// Customer never gets their order update
// TCP for reliable delivery of business data:
$socket = stream_socket_client('tcp://10.0.0.1:9000');
fwrite($socket, $orderConfirmation);
// TCP guarantees delivery — retransmits on loss
// UDP appropriate for real-time metrics:
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_sendto($socket, $metric, strlen($metric), 0, $statsd_host, 8125);
// StatsD: dropped metrics are fine — stream of data not individual records