Press "Enter" to skip to content

Once Again, Don't Use (include/require)_once

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

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

Some Notes on Yaf

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

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

PHP 5.5 May Introduce Generators

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

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

PHP and the Data URL Scheme

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

Filed in English, PHP应用
with 0 Comment