In my earlier post on PHP floats I missed one common question: why does intval(0.58 * 100) output 57? It's not a PHP bug — 0.58 is an infinitely long value in binary, so 0.58 * 100 comes out just under 58, and intval truncates it to 57.
with 0 CommentAPC's User Data Cache is bottlenecked by locks and performs like local memcached, so I built Yac: a shared-memory user data cache with lock-free reads (crc-validated), double hashing (MurmurHash) over chunked segments, and LRU eviction. In an ab test it ran ~7.7x faster than APC.
with 0 CommentWhy does this PDO bindParam loop insert 'weibo' for both columns? Because bindParam takes its second argument by reference, and the foreach $value variable keeps getting overwritten. Three ways to do it right: assign manually, use bindValue, or foreach by reference.
with 0 CommentA new mcrypt-based script responded very slowly under 20 concurrent requests while all server metrics looked normal. Cause: mcrypt_create_iv defaults to /dev/random, whose entropy pool is fed by system interrupts and can block when depleted. Fix: use MCRYPT_DEV_URANDOM (or rngd to refill the pool).
with 0 CommentYar is a lightweight PHP-extension RPC framework supporting msgpack/json/php packing protocols. Unlike xml-rpc or soap, its headline feature is concurrent calls: fire many requests at once with Yar_Concurrent_Client::call() + loop(), and a callback fires as soon as each returns — so you can process multiple data sources in parallel.
with 0 CommentBeyond the obvious 'include_once checks the loaded-files list' reason, there's a deeper one: PHP must open the file to obtain its opened_path before compile_file, so include_once triggers an extra open that APC can't skip. APC's include_once_override tried to fix this but was buggy. Plan for single-load yourself — using include_once just shows you don't trust your own code.
with 0 CommentYaf is a PHP-extension MVC framework I wrote two years ago to resolve the classic tension of using a framework while suffering a performance hit. On Baidu's products it proved stable, and migrating Weibo to Yaf raised TPS by 76%. A rundown of the design: a framework shouldn't need maintenance, debugging should be easy, it stays non-intrusive, and Yaf ships without an ORM by design.
with 0 CommentI once tried implementing yield for PHP back when I first joined the dev group but abandoned it — it needed major executor changes. Now Nikita Popov has fully implemented the RFC: Generators with a working patch in voting. A brief intro: a generator function uses yield to lazily produce each element and pause, resuming on the next iterator next() call — no need to materialize the whole array in memory.
with 0 CommentSince PHP 5.2.0, PHP's Stream wrapper has supported the Data URL Scheme (RFC 2397). Because nearly all file-operation APIs run on the stream layer, most of them accept a data: URL. So when an API only takes a filename but you already have the content in memory (e.g. exif_imagetype), pass a data:// URL with the base64 content instead of writing a temp file.
with 0 Comment