ExamplesFluent XML with the XP Frameworkat 2010-06-22 in Examples by friebeTo create an XML tree programmatically, the XP Framework has offered the xml.Tree class since its beginning in 2001. Recently, we've added a fluent interface to it, allowing for the following: <?php Merging XAR filesat 2010-01-30 in Examples by kieselWith the 5.7.7-RELEASE there has a nitfy small feature been added to the xar command: merging multiple XAR files. XAR files are the archives in which XP Framework applications can ship their classes and/or resource files in a way comparable to Java`s .jar-files. Combining multiple xar files into one can be handy one the one hand, because you can merge all dependencies and the application itself into one single file and only have to provide the one. On the other hand, for applications where startup or I/O performance is a concern, it can be useful: each xar file involved in an application comes with a startup time penalty - the file must be opened, the index must be read before the first file can be retrieved. Here, a single file instead of many files mean increased startup performance and less I/O calls of an application. This is how it works:
Reading gzip'ed websitesat 2010-01-08 in Examples by friebeTo reduce bandwidth some servers have their content zipped using solutions such as Apache's mod_deflate. This is done only if the Accept-Encoding request header contains the string gzip. Combining the XP Framework's peer.http API with the new io.streams.GzDecompressingInputStream one can accomplish this compression: <?php Compressing dataat 2010-01-06 in Examples by friebe The possibly easiest way to compress data in PHP is to use the string-in, string-out functions such as gzdeflate or bzcompress. For small number of bytes being passed in, this is fast and convenient, but it doesn't do well when working with large files, for example:<?phpIn one test I ran here, this piece of code used roughly 50MB peaks to compress a 26 MB input file. As of 5.7.7, the XP Framework will provide compressing output streams enabling you to compress one chunk at a time and saving more than 90% of memory: <?phpSure, this is more code, but it constantly uses not more than 0.5 MB while running. If you now have a look at the new io.streams.StreamTransfer class you can simplify the above code even more (and still save the memory). Type duplication in xpcli injectionsat 2009-10-14 in Examples, Announcements by friebeIt's just become another bit easier to write command line classes in the XP framework ("xpclis"). When using the @inject annotation you no longer have to specify the type parameter if you use a so-called "type hint" - so instead of writing the following: <?php...you can now omit the type part - it will be inferred from the first parameter's type: <?php New xml.Node::withChild() methodat 2009-09-21 in Examples by friebeTo easily create XML documents, the xml.Node class has been extended with a new withChild() method complementing addChild(). In contrast to the latter, withChild() returns the node the child was added to instead of the added child. (more) Unified runners in the webat 2009-08-11 in Examples, Editorial, Announcements by kieselThe XP framework had offered developers the power of an easy class loading setup via the new XP runners that are delivered with every release since several releases now. These runners have proven themselves very useful in day-to-day business, so we're working on porting them to the web! With the so-called web-runners these new cool and useful features will become available for you:
(more) Redirecting console outputat 2009-07-12 in Examples by friebeTo capture output written by any of the PHP functions the ouput control functions can be used (ob_start(), ob_get_contents() and friends). These functions do not affect the output made by the util.cmd.Console class as this writes directly to the standard out and error streams. To redirect these, you can use the following: <?php This can be useful in unittests, when running command line applications inside a web container or inside GUIs, or whatever other usecase you can invent Refactoring the old FTP API usageat 2009-06-30 in Examples by friebeIf you are running an XP release before 5.7.3 and are still using the old FTP API (e.g. FtpConnection::put(), FtpConnection::get(), etcetera), this will no longer work. These methods have been deprecated since October 2007 when RFC #0140 was implemented but have continued to work until recently. But as the FTP API has been rewritten and in this course these deprecated methods have been removed, now it's finally time to migrate! (more) Deadlock handlingat 2009-06-16 in Examples, Databases, RFCs by friebe The changes implemented in RFC #1059 make handling deadlocks easier. During deadlocks you might want to your program behave differently than during "regular" statement failures. For example, in Sybase, all transactions, regardless of their nesting level, are rolled back during a deadlock!You may have written sourcecode as follows in the past: <?phpThe problems should be obvious to the reader: The hardcoded errorcode (here the relevant one for Sybase), the very unelegant if, the missing portability for other drivers (PostgreSQL for example). (more) |
|