For Ajax 'fire-and-forget' operations that only need to report success/failure, use the HTTP status code itself as the answer instead of shipping a {status, message} JSON body: 204 No Content = succeeded, no data, don't refresh; 205 Reset Content = succeeded, clear the form. Laruence's note: 204 suits repeated updates of one item, 205 suits repeated form submissions — but no browser actually honors 205 (it's treated as 204/200).
with 0 CommentWhy a curl POST >1KB sometimes behaves oddly: libcurl first sends 'Expect: 100-continue' and waits for the server to acknowledge before sending the body. Servers that don't handle it (like lighttpd) return 417 Expectation Failed and break the logic. Laruence's one-line fix: suppress the header with curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')).
with 0 CommentA rebuttal to the viral claim that 'PHP's echo is slow'. Laruence's point: echoing a 500K string taking hundreds of ms has nothing to do with PHP (or its C implementation) — it's IO-bound, and IO speed caps the output speed. Turning on Apache's compression makes it faster simply because the string shrinks (high compression ratio), i.e. trading CPU for IO. PHP is genuinely innocent.
with 0 CommentWhy 'Compilation failed: support for \P, \p, and \X has not been compiled' shows up after a VPS migration: PHP/PCRE was built without Unicode property support, so the \pL regex in a search-highlight plugin fails to compile. Laruence's workaround is to drop \p{L} and match by explicit Unicode code-point ranges ([\x{41}-\x{5a}...\x{0800}-\x{d7a3}] with the u flag), plus a reference table of CJK/Korean/Japanese and GBK byte ranges.
with 0 CommentI've been busy developing Yaf (Yet another Framework), a Zend Framework–style PHP framework written as a PHP extension. The goal: a real-world showcase of the Zend API (classes, interfaces, inheritance, autoloading) that also solves the framework performance problem.
with 0 CommentHow does PHP's exception mechanism actually work, and what is the ZEND_HANDLE_EXCEPTION opcode at the end of every independently executable op_array for? A walk through what happens when an exception is thrown, how try/catch and user_exception_handler fit in, and why that opcode was gone from PHP 5.3 on.
with 0 CommentSomeone asked me today, saying he'd seen a PHPer talking about an unless statement. I was quite puzzled, until I learned that a well-known PHP guru abroad had hacked the PHP source himself and added an unless statement.
Interesting. So today I'll show you how to add an unless statement to our own PHP.