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.
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 CommentThe RFC I submitted to introduce the finally keyword into PHP was committed to the trunk. A quick rundown: finally removes the need to write cleanup twice (once in catch, once after), and — a gotcha — returning inside a finally overrides the return value from the try block. The code shipped with PHP 5.5.
with 0 CommentPeople keep proposing separating PHP's compile and execution steps for performance and code protection. My take: PHP compilation is already linear and fast, separation hurts instant-edit workflow, and APC/Zend O+ already give you that benefit. A real solution exists anyway — APC's apc_bin_dumpfile/apc_bin_loadfile export opcodes to .bin files you load on the server.
with 0 CommentWhy Laruence argues you should choose a language by how easy it is to pick up rather than how sophisticated it looks. A language is a tool whose value lies in letting you solve real problems fast; the more arcane the syntax, the larger the learning cost and the longer before you can ship anything. He contrasts C with C++ (Primer, Effective C++, the STL...), notes that PHP is more like C — one book, or even just the manual, is enough — and warns of the contradiction that mastering an advanced language needs project experience while project experience needs the language first. Don't put the cart before the horse: learn something easy and start solving real problems.
with 0 CommentA dev argued PHP releases all resources at request end so fclose/mysql_close are unnecessary. Wrong: in long-running or high-traffic contexts, holding connections until request end exhausts mysql.max_connections, file handles, and memory peak. Release resources as soon as you're done with them — if a PHP book says otherwise, burn it.
with 0 CommentAfter answering the same Yaf questions over and over, a roundup of commonly used resources for learning/using Yaf: official Chinese/English docs, the community forum and QQ/Google groups, the code-generator and class-signature tools, real-world examples, and the Windows dll releases.
with 0 CommentWhy does Foo::bar() called from inside a method still get a $this? Because in PHP, whether a call is static isn't decided by the '::' operator but by the calling scope. A '::' call made from within an instance context inherits that object's scope, which is also why parent::__construct() works the way it does.
with 0 Comment