Press "Enter" to skip to content

Zend Signal in PHP 5.4

PHP 5.4's new zend signal mechanism (per Rasmus's RFC) lets signal masking work in any SAPI and improves performance. Built on Yahoo's deferred-signal idea, it registers handlers for SIGALRM/SIGINT etc. at startup and defers them via a depth counter (zend_signal_globals_t.depth) instead of repeated sigaction calls, plus a new zend_signal registration interface.

Filed in English, PHP应用, PHP源码分析
with 0 Comment

Callable Type Hints

PHP 5.4's Zend Engine adds the callable type hint so a function can require a callable argument without manual validation — foo(callable $callback). Works with strings, closures, and [class, method] arrays; otherwise throws a catchable fatal. For extension dev, zend_parse_parameters gains the 'f' flag.

Filed in English, PHP应用
with 0 Comment

Array Dereferencing

PHP 5.4 adds array dereferencing (Felipe's change): you can now directly index into a returned array — $mid = foo()[1] — instead of the old list(, $mid, ) = foo(); or a temp variable. It also works with references, e.g. getTable()["foo"] = "laruence" when the function returns by reference.

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

Introducing the mysqlnd_ms Plugin

mysqlnd_ms, a mysqlnd plugin (from the MySQL team: Andrey, Ulf Wendel, johannes), does read-write splitting and load balancing by inspecting queries — reads go to slaves, writes to the master. Configure master/slave in the plugin's ini (JSON from 1.1.0) and connect via a section name like mysqli("myapp", ...). Requires mysqlnd, the default driver since PHP 5.4 beta1.

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

Recursive Patterns in PHP Regex

Can a regex match balanced brackets? Perl 5.6+ introduced recursive patterns: the (?R) symbol refers to the pattern itself, so #\((?R)*\)# matches arbitrarily nested balanced parens — but you must always give the recursion a terminating condition (e.g. (?R)* not (?R), else it tries to match infinitely). Also supports numbered references like (?3).

Filed in English, PHP应用
with 0 Comment