Press "Enter" to skip to content

Using HTTP 204 and 205

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).

Filed in English, Js/CSS, PHP应用, 随笔
with 0 Comment

Expect: 100-continue

Why 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:')).

Filed in English, PHP应用, 随笔
with 0 Comment

PHP is Innocent

A 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.

Filed in English, PHP应用, 随笔
with 0 Comment

Compilation failed: support for \P, \p, and \X has not been compiled

Why '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.

Filed in English, PHP应用
with 0 Comment