Real-Time Updates with Plain PHP: Server-Sent Events
WebSockets need infrastructure. Polling hammers your server. SSE streams live updates over normal HTTP with a PHP file and the built-in EventSource API - reconnection included.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
WebSockets need infrastructure. Polling hammers your server. SSE streams live updates over normal HTTP with a PHP file and the built-in EventSource API - reconnection included.
Escaped slashes, mangled unicode, silent failures returning false - json_encode ships with defaults from another era, and five flags fix all of it.
strtotime and DateTime parse a small English grammar - "last day of next month", "second friday of january" - that replaces whole functions of calendar math.
Comparing secrets with === leaks how many leading characters matched, one microsecond at a time. hash_equals exists for exactly this, and knowing when to use it is the whole trick.
A PHP script renamed to photo.jpg sails past extension checks. finfo reads the actual bytes. Here is the upload validation layer cake that actually holds.
Sending the confirmation email should not make the customer stare at a spinner. PHP can close the HTTP response and keep working - if you know which runtime you are on.
ob_start() plus include turns any PHP file into a string-returning template - the exact mechanism template engines are built on, useful raw for emails, PDFs and HTML fragments.
match() is not just a stricter switch. Feed it true as the subject and every arm becomes an arbitrary condition - an elegant, exhaustive replacement for elseif ladders.
The third parameter turns array_column into a re-indexing tool, it reads object properties, and combined with array_map it handles most of your collection reshaping.
FETCH_KEY_PAIR, FETCH_UNIQUE, FETCH_GROUP and FETCH_COLUMN reshape query results at fetch time - the id-indexed maps and grouped arrays you keep building with foreach loops.
Fire five parallel AJAX requests at a PHP backend and watch them execute one... at... a... time. The culprit is the session file lock, and the fix is a single function call.
file() and fetchAll() load everything into RAM and die on big datasets. Generators stream one row at a time with constant memory - and the code barely changes.