Every project, small or big, has some configuration in the form of keys and their associated values, commonly defined using constants. These configuration settings normally get loaded upon each request, making them a good target for optimizations.

The contenders

By default, PHP supports defines and class constants, but extensions such as APC and hidef can give you a better performance if enabled. The APC extension has a function to define constants using an array, called apc_define_constants(). The hidef extension is different, it reads the constants from a set of files during PHP initialization; this makes the constants available at compile time for immediate substitution.

Setup

To test the four aforementioned methods, I've chosen a simple set of operations using the most commonly used types of constants: integers, strings and doubles. The script would then run those operations in a tight loop for a fixed number of iterations and record CPU time and memory consumption. Lastly, the APC extension is not being used as an opcode cache for this test. The outcome reveal that the define() method yields the longest running time while class constants method yields the higher memory consumption; the results of those methods are therefore used as the benchmarks for the other results.

Performance results

Test performedTime spentMemory consumed
Using define()100%32.6%
Using class constants30.2%100%
Using apc_define_constants()24.2%32.0%
Using hidef13.9%13.5% (*)
(*) hidef consumes memory during initialization, but this was not taken into account for this test

Analysis

The clear winner of this test is the hidef extension; upon initialization it creates constants that are both persistent and available during the compilation phase. The results opcode is superior to any of the other methods described above. However, all this goodness comes with a drawback: configuration settings are instance wide, which impacts all setups of PHP that runs beyond a single web request (e.g. Apache module or FastCGI). Using apc_define_constants() is a good runner up in terms of performance (6% faster than class constants) and memory consumption (comparable to using define). It uses optimized code to create constants, speeding it up threefold. Some people may still use eAccelerator and/or Zend Optimizer, but APC is much more actively developed and has additional features to work with variable caching (like Memcached but only server wide). And it will be integral part in the upcoming PHP6 (or whatever they're going to call it). In the bottom two we still see a substantial difference in execution time between class constants and using define(). Using class constants has the benefit of being available during execution time, which makes it a prime candidate for further optimization using APC. However, the OO nature of this method has two drawbacks: resolving the constant still needs to take place during run-time and there's more memory consumed (at least three times that of the runner up).

Conclusion

If you're only running one site per web server instance or you can namespace your constants, choose hidef. If you're already using the APC extension or interested in doing so, choose apc_define_constants(). If you don't mind the extra memory consumption to yield 300% CPU time improvements, choose class constants.

Introduction

Ever since CSS was first published many years ago to separate content from presentation its basic structure and "language" features have hardly changed. Tools such as Sass and Less aim to remedy some shortcomings, such as:

Variables - often you find yourself declaring the same dimensions or positions within your document (or even across documents), making it more difficult to change them later
Inheritance - nested rules require repetition of selectors, adding to the clutter
Operators - addition, subtraction and other functions can be helpful to add relationships between definitions


Making a choice

Both are great tools and make it easier for us developers to author CSS.

Since most of our code is based on jQuery, I was tasked to find a way to retrieve and modify an element's HTML contents.

Normally I would use html() for this purpose, but in this case I needed to operate on the HTML including the surrounding element, the so called outer HTML.

PHP exposes a great SOAP client to consume remote services, taking away much of the complexities involved in constructing your requests and deciphering the responses; it particularly shines when used in WSDL mode.

However, in the case of single element arrays, it doesn't work as expected. It will return an object instead.

The accepted standard way of passing any data to JavaScript is via json_encode(); this ensures proper encoding is applied when it's decoded on the other end. Handling arrays is not much different, except that the amount of data getting sent isn't always expected.

Last week we launched a point release while working towards the next version. This release fixes bugs that were reported by our users and some other improvements and features. Have you ever wanted to download a DVD of a single muvee uploaded with muvee Reveal? Now you can! While viewing the muvee on the website, the right panel will show a link to download an ISO image of the muvee.

Every project, small or big, has some configuration in the form of keys and their associated values, commonly defined using constants. These configuration settings normally get loaded upon each request, making them a good target for optimizations. The contenders

By default, PHP supports defines and class constants, but extensions such as APC and hidef can give you a better performance if enabled. The APC extension has a function to define constants using an array, called apc_define_constants().

Yesterday's release also initiated a design overhaul process to improve user experience. The first goal was to group all media related actions right next to the item you're viewing, actions such as tag, rotate, share, etc. After moving the media actions we realized that the album toolbar had more empty space to enlarge the navigation tool (the drag bar to seek into your album).

We've had many requests from our users asking how to share their album with either a large group of friends (of whom you're bound to miss a few) or a group of people you may not even know (e.g. users from a forum or newsgroup). With the introduction of viewers in last year's release we are now able to present the next major feature in line; album sharing.

Last year we introduced Facebook integration on our site; ever since, we have been trying to make the experience as smooth as possible - which is not always straightforward as Facebook is going through quite a few changes in the next few months. One of those efforts has gone into simplifying the way you visit shwup albums by following invites from other Facebook friends.

I'm happy to announce the last point release of shwup.com for this year! We made just a few changes, but we think they're worth it for all those photos and video you're going to upload in the new year ;-) The major change is that we've changed the way media titles are shown and updated. After a good look at the current page design we realized that showing the titles at the top of the page wasn't that great; therefore, we now show them in a more logical spot: underneath the photo.
Blog Archive
Contributors
Contributors
Loading