Laruence's first task after joining the PHP dev team: implement foreach($array as $k => list($a, $b)) via a grammar rewrite. He shared the RFC and a PHP 5.4 patch, but the feature lost the 5.4 vote (9 for, 19 against). Notes that 5.4's parser data structures changed a lot — a heads-up for anyone studying the Zend engine.
with 0 CommentSince PHP 5.3, zend_parse_parameters gained new descriptors: f (callback, returns zend_fcall_info + cache), H (array or HASH_OF(object) — lets an object be accepted where an array is expected), L (clamped long), Z (raw zval**), and * / + (0-or-more / 1-or-more variadic args). Cuts down the manual validation you used to do for callbacks and objects-as-arrays.
with 0 CommentA PHP 5.4 alpha1 feature roundup: Traits (lightweight method reuse via 'use', with fixed conflict-resolution rules), array dereferencing ($a = explode(...)[0], and even lvalue use), DTrace support, plus the new built-in Webserver SAPI (php -S localhost:8000). Also notes the removals: break/continue $var, register_globals, etc.
with 0 CommentA hands-on walkthrough of pulling useful info out of a PHP core dump with gdb: read the signal/backtrace, use execute_data->function_state to get the crashing function name/file/line, inspect EG(argument_stack) for the last call's args (they don't map 1:1 to gdb frames), and lean on the .gdbinit helpers (zbacktrace, print_ht, zmemcheck).
with 0 CommentLaruence's four takeaways from a PHP performance talk: (1) optimization advice is about nipping problems in the bud while coding, not a rulebook to apply after a problem appears; (2) advice is a guard against abuse, not a law — e.g. batch assign() beats repeated __set magic calls; (3) advice is language-specific — an interpreted language does none of the compiler optimizations C does, and every symbol costs a Hash Lookup; (4) dig to the bottom — one high-level statement may compile to hundreds of lines of C.
with 0 CommentThe open source version of Ap — the framework I introduced at the 2011 PHP Technology Summit — is finally released as Yaf 2.0. Here are the source code and manual links; a dedicated documentation site is coming.
with 0 CommentCan you cap a slow query so it doesn't blow out PHP's max_execution_time? Yes — libmysql's MYSQL_OPT_READ_TIMEOUT (value 11, read from the enum), but only mysqli exposes mysql_options() to PHP, so you pass the numeric constant directly: $mysqli->options(11, 1). Laruence's catch: libmysql retries twice, so the effective timeout is 3x what you set — the practical floor is 3s.
with 0 CommentPHP FPM's fastcgi_finish_request() ends the client response and closes the connection but lets the PHP script keep running server-side — use it to defer logging, transcoding, or other post-render work off the critical path. Laruence's note: it's cleaner than flush() for this, and a function_exists() shim keeps the code portable to non-FPM environments.
with 0 CommentLaruence's 17 hand-picked PHP performance/correctness tips: list() to skip explode() segments, NULL === over is_null, prefer === over ==, avoid continue, watch out for loose comparison in switch/in_array (strval the value, or pass a 3rd arg), use switch(TRUE) for if/elseif chains, define before use (undefined vars are 8x+ slower), swap without a temp, ~~ is ~3x faster than floor (but overflows on big numbers), do{}while(0) blocks, minimize @, avoid recursion, $_SERVER['REQUEST_TIME'] over time(), hoist strlen() out of the for-condition, prefer strncasecmp/strpbrk/stripos over regex, brace variables in double-quoted strings, and use FALSE for errors vs NULL for 'not found'.
with 0 Comment