PHP, the universe and all the rest - PHPIs it really that hard ...? (or how i finally learned to hate CSS) (24.8.2010, 09:09 UTC)

I confess that i've been hiding under a stone for quite some time when it comes to contemporary HTML stuff, for most of the things i'm doing on the presentation level even good old HTML 1.0 would be sufficient if it weren't for the occasinal tabular data ...

So while i know CSS in theory i've never really looked into the black magic of doing CSS layouts and stuff ... until now ...

What i'm up to right now was to produce a small series of step by step examples on how to use OpenLayers to present customized OpenStreetMap based maps, and for that i wanted to have a simple layout like this:


Continue reading "Is it really that hard ...? (or how i finally learned to hate CSS)"
Link
Travis SwicegoodRazors and Development (24.8.2010, 05:00 UTC)

A few years ago I switched to an old fashion safety razor and haven’t looked back. The latest entry into the razor market has reaffirmed my decision as the right one.

The new Pro Glide from Gillette only costs less than $10 to purchase. Good deal, right? Nope. The replacement blades cost $3-$4 each! Assuming you get a few weeks out of each blade, you’re looking at paying between $6 and $10 every month to use this razor blade.

It’s a great deal—for Gillette.

I use Merkur razor. I paid a lot, comparatively speaking, up front but I can buy better quality razors for less than $0.75 each. They last a lot longer and I end up with a much better shave.

I view the trade-off here as the same one you have to look at when deciding what framework you choose to develop your code in. There are a lot of frameworks that provide a lot of help getting off of the ground. It almost seems too easy.

Write your on custom blog in 5 minutes? Sure! Want to have a RESTful API? Add a couple of classes, some new routes, mark as complete.

Look at the framework and read some of the comments from its detractors. Those complaining generally have one of two problems:

  1. They’re going to complain about anything, they’re just ranting. Ignore these people.
  2. They’ve hit a legitimate pain point in the framework where they deviated too far from the intended use. Pay attention to what these people are talking about.

If you’re application is significantly complex, no off-the-shelf framework is going to do everything you need it to. Some frameworks may even get in the way. Make sure you realize the trade-offs before you commit.

What makes a good framework?

The best ones serve as scaffolding—in the original meaning.

… a temporary structure used to support people and material in the construction or repair of buildings and other large structures.

Put another way for software development:

… helps you ramp up quickly, then gets out of the way.

Historically, frameworks manage the first part of this well. That’s where they shine. It’s the last part that they’ve had a problem with.

Django manages both of these well. My one complaint with it is that it manages the latter part better than the first. There’s a lot of boilerplate needed to get started, but I can live with that. When my applications outgrow Django, removing Django from the equation is easy with one exception.

Models.

Models are like your razor’s blades. Without blades, your razor doesn’t shave; without models your application doesn’t have any data to work with. The fix I’ve found works best for me is to keep my models then and put all of my logic for operating on them in other areas of the code base.

This separation helps me keep my business logic portable. I might be using the cheap route to get started, but the heavy lifting goes with me if I decide something else is a better fit.

Link
Web Development Blog » PHP scripts5 Useful jQuery Snippets for your Website (23.8.2010, 20:22 UTC)

jQuery is a popular JavaScript library which is used by many developers and applications. While using jQuery you need to write less code, writing functions is less complex and there are a lot of plugins you can use for free in your web application. Even if you code everything by yourself, you need only a few rows of code to create nice and powerful features for your website. If you’re in hurry check the jQuery demo page.

Populate select menus with jQuery and Ajax

One of the most powerful jQuery function is the Ajax Suite. This example shows how-to populate a second select menu based on the option from the first select menu.

Just in case we have this select menu with the main categories:

<form>
        <label for="category">Choose: </label>
        <select id="category" name="category">
                <option value="fruit">Fruit</option>
                <option value="grain">Grains</option>
                <option value="vegetables">Vegetables</option>
        </select>
</form>

If someone has changed the value for this select menu, we want to show the equivalent menu inside the span element with the ID “subcat”. To do this we use this jQuery snippet that makes an Ajax request to a PHP file called “getSubCat.php”. After the select menu is changed a loading image will show up (in case of slow Internet connections), the PHP script is called and the sub-select menu becomes visible.

$(document).ready(function() {
        $('#category').change(function() {
                var category = $(this).val

Truncated by Planet PHP, read more at the original (another 29362 bytes)

Link
Bradley HoltVermont Code Camp (23.8.2010, 13:23 UTC)

This year’s Vermont Code Camp will be on Saturday, September 11th, 2010 at Kalkin Hall on the University of Vermont campus. Last year’s event was a big success with 85 attendees and 19 sessions and this one promises to be even bigger and better! The second annual Vermont Code Camp will be a full day event bringing together technology community members, students, and professionals from around Vermont and beyond.

Vermont Code CampThere will be four rooms with sessions on .NET, PHP, Ruby, Python, Java, and more. Two of the rooms will have .NET topics and another will have sessions on free/open source software. There will be a fourth room where developers will be introduced to various technologies that they may not use every day. For example, are you a .NET developer? Come and learn about PHP, Ruby, Python, or Java. A Ruby developer? Learn about .NET, PHP, Python, or Java. You get the idea.

Vermont Code Camp is a great way to bring together technology user groups from around Vermont. The Vermont.NET User Group is the primary organizer of the event but we hope to see others from the Burlington, VT PHP Users Group (which I organize), the Vermont Ruby On Rails User Group, the Vermont Area Group of Unix Enthusiasts (VAGUE), the Green Mountain Oracle Users Group, the New England Adobe User Group, and the VT SQL Server Users Group there. Do you know of any other Vermont technology user groups? Please let me know so that we can invite them!

Link
Johannes SchlüterHashTables (22.8.2010, 21:52 UTC)

In case you ever heard me talking about PHP internals I certainly mentioned something along the lines of "Everything in PHP is a HashTable" that's not true, but next to a zval the HashTable is one of the most important structures in PHP. While preparing my "PHP Under The Hood" talk for the Dutch PHP Conference there was a question on IRC about extension_loaded() being faster than function_exists(), which might be strange as both of them are simple hash lookups and a hash lookup is said to be O(1). I started to write some slides for it but figured out that I won't have the time to go through it during that presentation, so I'm doing this now, here:

You all should know PHP arrays. They allow you to create a list of elements where every element may be identified by a key. This key may either be an integer or a string. Now we need a way to store this association in an effective way in memory. An efficient way to store a collection of data in memory is a "real" array, an array of elements indexed by a sequence of numbers, starting at 0, up to n. As memory is essentially a sequence of numbered storage blocks (this obviously is simplified, there might be segments and offsets, there might be virtual pages, etc.) we can efficiently access an element by knowing the address of the first element, the size of the elements (we assume all have the same size, which is the case here), and the index: The address of the n-th element is start_address + (n * size_of_element). That's basically what C arrays are.

Now we're not dealing with C and C arrays but also want to use string offsets so we need a function to calculate a numeric value, a hash, for each key. An hash function you most likely know is MD5, MD5 is creating a 128 bit numeric value which is often represented using 32 hexadecimal characters. For our purpose 128 bit is a bit much and MD5 is too slow so the PHP developers have chosen the "DJBX33A (Daniel J. Bernstein, Times 33 with Addition)" algorithm. This hash function is relatively fast and gives us an integer of the value, the trouble with this algorithm is that it is more likely to produce conflicts, that means to string values which create the same numeric value.

Now back to our C array: For being able to safely read any element, to see whether it is used, we need to pre-allocate the entire array with space for all possible elements. Given our hash function returning a system dependent (32 bit or 64 bit) integer this is quite a lot (size of an element multiplied wit the max int value), so PHP does another trick: It throws some digits away. For this a table mask is calculated. The a table mask is a number which is a power of two and then one subtracted and ideally higher than the number elements in the hash table. If one looks at this in binary representation this is a number where all bits are set. Doing a binary AND operation of our hash value and the table this gives us a number which is smaller than our table mask. Let's look at an example: The hash value of "foobar" equals, in decimal digits, to 3127933054. We assume a table mask of 2047 (2¹¹-1).

  3127933054    10111010011100000111100001111110
&       2047    00000000000000000000011111111111
=        126    00000000000000000000000001111110

Wonderful - we have an array Index, 126, for this string and can set the value in memory!

If life were that easy. Remember: We used a hashing function which is by far not collision free and then dropped almost two thirds of the binary digits by using the table mask. This makes it rather likely that some collisions appear. These collisions are handled by storing values with the same hash in a linked list. So for accessing the an element one has to

  1. Calculate the hash
  2. Apply the table mask
  3. locate the memory offset
  4. check whether this is the element we need, traverse the linked list.

Now the question initially asked was why extension_loaded() might be faster than function_exists() and we can tell: For many random reasons and since you have chosen a value which probably conflicts in the first, not in the second. So now the question is how often such collisions happen for this I did a quick analysis: Given the function table of a random PHP build of mine with 1106 functions listed I have 634 unique hash values and 210 hash values calculated from different functions. Worst is the value of 471 which represents 6 functions.

Full results are

Truncated by Planet PHP, read more at the original (another 723 bytes)

Link
Ulf WendelPHP @ FrOSCon: the power of mysqlnd plugins (22.8.2010, 20:32 UTC)

Slowly the power of mysqlnd plugins becomes visible. Mysqlnd plugins challenge MySQL Proxy and are often a noteworthy, if not superior, alternative alternative to MySQL Proxy for PHP users. Plugins can do almost anything MySQL Proxy can do - but on the client. Please find details in the slides. The presentation has been given today at the PHP track at FrOSCon.

The biggest news is certainly the work from David Soria Parra. David made it possible to write mysqlnd plugins in PHP! No C coding skills needed. It can’t get any easier. Insipired by the hints given in the C mysqlnd plugin API documentation he and his employer Mayflower decided to develop the “mysqlnd_uh” PECL extension. “mysqlnd_uh” stands for “mysqlnd userhandler”.


class QueryLogger extends MysqlndUhConnection {
        
  public function query($res, $query) {
    error_log($query);
    return parent::query($res, $query);
  }
        
}
        
mysqlnd_uh_set_connection_proxy(new QueryLogger());

Assume you have installed a PHP application and you want to know what queries it runs. Using PECL/mysqlnd_uh it is as little as the above code needed to audit the application. Install PECL/mysqlnd_uh, put the code in your auto_prepend_file and find the queries in your error log. This works with every PHP application running on PHP 5.3.3 or newer. It works without touching the application. Not having to change the application itself makes updates much easier. Whenever the application vendor releases a new version you can just install it. Your QueryLogger is not part of the application. It will continue to work after the application update.

Query logging is trivial. Even load balancing or failover should be easy to implement. Future will proof, stay tuned!

Link
Lorna MitchellWorking with Web Services - Froscon 2010 (22.8.2010, 12:21 UTC)
This weekend I'm at froscon in Germany, giving two talks. One had no slides (but may have video, if I see it then I will post the link here) and the other was "Working with Web Services" which I gave this morning in the PHP room. My slides are here:



Thanks to the PHP room organisers for accepting me as a speaker and to Sebastian for twisting my arm in the first place - it's a fun event!
Link
Tobias SchlittFrOSCon 2010 slides online (22.8.2010, 12:12 UTC)
I uploaded my slides about the Apache Zeta Document component to Slideshare. The talk was held yesterday in the PHP room at FrOSCon.
Link
blog.phpdeveloper.org » PHPNew @ Joind.in – Widgets! (22.8.2010, 01:59 UTC)

With the latest site release over on Joind.in, we've added something a bit more fun for users of the site - handy little widgets that let you embed information from the site into yours. You can see an example of it if you look to the right (well, if you're looking at the site not the feed, of course).

The widgets currently let you do a few things with a few different bits of information:

  • talks
  • events
  • and users

Each of the widgets comes in different sizes (some are still in the works) and right now you can use a small and large template for the talks, a large template for the events and a large template for the user information. The example I've put here on the site is a user widget that lists the talks I've claimed on the Joind.in site and the ratings they've been given. Here's how I called it:

PHP:
  1. <script src="http://joind.in/inc/js/widget.js" id="joindin_widget"></script>
  2. <script>joindin.display_user_large(1);</script>

Pretty easy, huh? Well, you can find out more about the widgets on the Joind.in site here: http://joind.in/about/widget

For those interested in how it all works, I'm working on a post detailing each of the pieces. If you'd like to look more into the templating used, check out mustache (javascript).

If you haven't heard of Joind.in and are involved in events (or speaking) at all, you should check it out! The site lets you give and get real-time feedback on presentations!

Link
Christian WeiskeFirst SemanticScuttle PEAR package (21.8.2010, 23:52 UTC)

FrOSCon is still running, even though it's after midnight now. After the party I was not really tired so I continued to hack on the PEAR package for SemanticScuttle. The hard task was to get the phing build script to generate it correctly. The pearpkg2 task that is shipped with Phing is totally unusable, so I had to drop that and use Phing_d51PearPkg2Task as we do at work.

Only two hours later, package generation via phing is fully working. I can run the pear-installed SemanticScuttle without any problems, and even running the tests via pear run-tests -pu __uri/semanticscuttle is working flawlessly! The build.xml changes are in SVN now.

The package of the current version 0.97.0 can be found on my server. Please note that the channel is currently __uri since I did not yet setup a channel server. That will change soonish.

Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP