P'unk Avenue Window

Archive for ‘Development’

Faster, PHP! Kill! Kill!

March 8th, 2010 by Tom 10 Comments


PHP is easy… as programming languages go, that is. You can build sites in a real hurry.

With frameworks like Symfony, you can build them faster still, and follow modern programming practices at the same time.

And Apostrophe strips away yet another layer of effort if your site calls for a content management system.

Yes, Java has more raw speed, all else being equal (which it never is). But as the LISP programmers used to say, “a moment of regret, a lifetime of convenience.”

Still, sooner or later success catches up with you and you want your site to cope with Serious Traffic… or cope with moderate traffic on a cheap virtual machine… or at the very least, not be dog-slow with just a handful of users on the system.

There’s a lot of advice out there about optimizing PHP code, some of it well worth your while. And there’s excitement about HipHop, Facebook’s new native code compiler for PHP. But these are drastic steps that require you to rewrite your code or adopt less proven and more awkward ways of delivering your code.

Justified? Sure, sometimes, on the biggest projects in the world (like Facebook) (*). But as Donald Knuth says, “premature optimization is the root of all evil.” That’s because tweaking your code for speed’s sake usually makes it harder to maintain and less adaptable to new requirements.

What most developers don’t realize is that there are three major factors that typically slow down PHP projects based on frameworks (like Symfony or, sigh, Drupal) so much that code profiling and database query redesign don’t even have a chance to become relevant factors. Fix these things first before you worry about other issues:

1. Compiling code over and over and over. Would you wait for your Mac to recompile MacOS X from source code every time you boot it up? Of course not. How about every time you fill out a dialog box? That’s pretty much what you’re doing every time you access a PHP-driven website that doesn’t use a bytecode cache.

2. Waiting and waiting and waiting for web browsers to make another request, pinning down web server processes that your other users need. By default Apache usually lets browsers hold on to a connection for up to 15 seconds just in case they ask for more. This is a good thing in many ways, but 15 seconds is far too long. Which leads us to #3:

3. Tying up a “fat” web server process with PHP on board for every request, even requests for the zillions of little static PNGs that probably make up your page design. (**) A typical Apache web server configuration with mod_php suffers from this flaw, fatally limiting the number of simultaneous users you can handle.

So what can we do about these problems? Quite a bit as it turns out. I’ll start with the low-hanging fruit and move on to the tougher stuff. The fascinating common thread with all of these suggestions: no changes at all to your PHP code.

(more…)

Choice is a good thing

February 24th, 2010 by Tom No Comments

Just a quick note in response to Lukas Kahwe Smith’s recent comments about the “problem” of multiple CMSes for Symfony. This note began as a comment of mine on Lukas’ blog.

We developed Apostrophe to scratch our own itch: we needed a CMS that our clients could use to add content to their sites in a variety of ways without inadvertently breaking the site design. So our CMS concentrates on the admin’s user experience, extending metaphors already present in the page. It’s about design even more than it’s about software architecture.

We also wanted to make sure it supported Symfony coding practices we were already having good success with. Therefore slots and engines implemented as Symfony modules, not new abstractions, and a clear lineage back to ideas from sfSimpleCMS.

We open sourced Apostrophe because we saw a win-win situation: other developers are in the same boat (their clients are also frustrated with Drupal administration, and they need a good solution today).

More eyes on our code, more bug reports, more suggestions equals a better system for everyone in the Apostrophe community.

Right now this is working for us in a big way, and it’s running in production on a number of client sites. Others on the apostrophenow google group are also happy with it (although they have valid criticisms that we are addressing), and they are building client sites that work. There’s no business case for us to screech to a stop and start doing something radically different.

Right now we have a team of seven people doing great work with Apostrophe and no interest in stopping that. Evolving it to be better, eventually rewriting it extensively in the Symfony 2.0 timeframe… sure! But unless the marketplace tells us otherwise, we’re going to keep doing good business, writing good code and sharing our work with those who like our approach.

Joomla, Wordpress and Drupal are all thought of as CMSes for PHP, but no one is telling them that they must merge. Why? People pick the project that works best for their needs. That’s as it should be. Software architecture isn’t the only differentiating factor between content management systems.

If you like Diem or Sympal’s approach better, heck, go ahead and use ‘em. A “there can be only one” approach leads to design by committee, and that is not always a good thing.

#slive2010 Liveblogging: Fabien Potencier: Symfony 2.0

February 17th, 2010 by Tom 6 Comments

I am liveblogging Fabien Potencier’s Symfony 2.0 presentation. Bear with me and my editorial errors, simplifications and bare-faced libels.

My own opinions are in parentheses.

They are setting up now.

“Symfony 2.0 Reloaded” Preview Release

“I’ve decided to do the session in French” heh

In 10 minutes you will discover the shiny new version of Symfony, Symfony 2.0. Symfony 2 is just awesome. But first a bit of history.

Symfony 1.0 released in January 2007. Started as glue between existing libraries: Mojavi, Propel, Pardo i18n, …

“How many of you are still using 1.0?” [Some hands go up] “Ohhhhh!” [Hey, I raised my hand too, I have to support existing projects after all, heh. Our new stuff is all 1.4]

With Symfony 1.2 in November 2008, decoupled but cohesive components wre rolled out: forms, routing cache, YAML, ORMs… but still the same core.

Symfony 1.4 – November 2009. Added polish on existing features. Removed the support for deprecated features. Current LTS released, maintained until late 2012.

What is Symfony 2.0? The next version of course… except Symfony now takes an ‘S’ instead of an ’s’. That’s the big difference!

Talk about Symfony 2 with a capital S please! Symfony 1 (uppercase) does not make any sense, symfony 2 does not make sense! It’s all about Symfony 2. “I’m quite picky.”

“Same philosophy, just better.” We’ve learned a lot from our mistakes. We’ve learned a lot… we have problems with Symfony 1, but not all are fixable. It requires breaking backwards compatibility. So we need to go forward.

Symfony 2 is still an MVC framework.

It’s probably more of a Fabien-style framework than anything else (his words not mine (: ).

MTV: Model, Template and View?

Highly configurable and extensible. Same Symfony Components (DI, events, request, etc), same great developer tools, full featured.

Everything is upgraded to PHP 5.3. (Great, I hope they debug PHP 5.3 by the time Symfony 2.0 is complete!)

OK, but why a major version # change then?
(more…)

Doctrine 2: Jonathan Wage at #sflive2010

February 16th, 2010 by Tom 1 Comment

I’m attending Symfony Live. Below are my notes from Jon Wage’s presentation on the upcoming Doctrine 2.0. My more opinionated, less explanatory comments tend to be in parentheses. Everything paraphrased brutally to keep up.

“Not the same old PHP ORM”

100% re-written codebase for PHP 5.3

“Are you scared? You shouldn’t be! Change is a good thing!”

5,000 records hydrate in 1.4 seconds. Whee!

10,000 records in 3.5 seconds.

Twice the data and still faster than Doctrine 1.

% improvement over Doctrine 2 is big. PHP 5.3 is a big win with a heavily OO framework. Better optimized hydration algorithm. New query and result caching implementations. All around more explicit and less magical code. Killed the magical aspect of Doctrine 1.

“The only valid measurement of code quality: WTFs/minute”

Good code: “WTF….. WTF”

Bad code: “WTF WTF WTF WTF WTF WTF”

(more…)

#sflive2010 Geoffrey Bachelet, Symfony Internals

February 16th, 2010 by Tom 2 Comments

I’m attending the Symfony Live conference. Below are my notes from Geoffrey Bachelet’s presentation on Symfony Internals. Geoffrey Bachelet wrote the “Symfony Internals” chapter of the Symfony book.

He wrote the Symfony Internals chapter

Customizable, flexible, extensible

Extensible through plugins, events, and overriding entire framework classes

The bootstrap retrieves application configuration, then instantiates sfContext and calls the frontend controller

sfContext implements the Singleton design pattern. Has pros and cons: mostly cons. Testability issues. Responsible for loading factories.

Application configuration: frontendConfiguration extends ProjectConfiguration, shares methods and constructors. Most customization happens in ProjectConfiguration.

ProjectConfiguration crewates an event dispatcher, then loads plugins.

sfEventDispatcher is available as a separate component. Implements the Observer design pattern. An object can register interest in events.

autoload.filter_config event allows you to customize the autoloader configuration.

There are more than 900 plugins in the repository today.

settings.yml holds all framework leve settings, there are a lot of them. Actions, security strategies, I18N, debug bar, etc.

app.yml is for your use. config/app.yml is a project wide app.yml, we rarely use that.

Environments allow you to specify different behavior for different environments. Different database, mailer strategy, etc.

(more…)

Symfony live: John Cleveley on the admin generator

February 16th, 2010 by Tom 4 Comments

John Cleveley @jcleveley on the Symfony admin generator
@jcleveley gave an excellent talk on the Symfony admin generator at #sflive2010. Here are my notes.

View more presentations from jcleveley.

He’s using Zend Framework at the moment but has done a lot of good Symfony work in the past

“Backend development” photo of a zoopeeper holding up a trash can to an elephant’s rump very nice.

John worked with the NHS for a while, they were using Excel spreadsheets for complex workflows, web apps were a big change for the better

A big fan of the admin generator: “it’s super awesome”

Provides most common admin requirements out of the box (CRUD: Create, Retrieve, Update, Delete actions to manage more or less any type of information)

Can be extended to meet bespoke needs

What’s new since 1.0? “Completely re-written for the form framework”

(more…)

Thomas Rabaix: internationalization and Symfony

February 16th, 2010 by Tom No Comments

Hi folks, I’m attending Symfony Live 2010. These are my notes from Thomas Rabaix’s talk on internationalization in Symfony, with a few offhand remarks of my own.

Thomas Rabaix talk on internationalization

URL: routingModel: doctrine + propel
Form: sfForm

Most of the 18n is based on Prado framework
ICU data updated in sf1.3/sf1.4
You need

all:
  .settings:
    i18n: true
    default_culture: en

Culture detection

HTTP request -> culture in URL

If no culture in URL, culture in session

What about culture in the header?

Updates sfRouting, sf18n, executes controller

We’re not big on culture in URL in apostrophe since the session can do it but it’s nice to be able to bookmark.

sfContext::getInstance()->getUser()->setCulture('fr')

Notify the user.change_culture event (this doesn’t do the changing, it just notifies other things that care; why doesn’t setCulture do this for us?)

recipe_esarch:
  url: /:sf_culture/recipe/view

Example: /en/recipes/search => sf_culture = en

(more…)

Apostrophe 1.0!

February 11th, 2010 by Geoff 3 Comments

We have labored long and hard to prepare for the 1.0 release of Apostrophe. As we said before, it has been stable and in use for a long time now, but we wanted to mark a moment in time with an official release.

Probably the easiest way to get a feel for Apostrophe is to go to our demo site and login. The user name is “admin” and the password is “demo”. Keep in mind that the content resets itself every hour on the hour.

If you want to get your bearings before you you do that, head over to the newly revamped Apostrophe site. For the very interested, you should consider checking out our extensive README which includes an Installation section, an Editor’s guide, a Designer’s guide and a Developer’s guide.

Now for some of the highlights.

Slots!

Apostrophe Slot Buttons

There are rich text, image, slideshow, video, button, PDF, Raw HTML, and other slots built in. If you have used Apostrophe before, you know that you can add a slot on a page, choose what you want to place and then reorder it. New custom slots can also be made for any project.

Slot Options

Apostrophe Slideshow: Compact Option

For some time we have wanted to be able to give you more fine control of a specific slot. For instance, what if you wanted to make the background color of a some text slots yellow, and some white? In the past that would have required two slots. Now, it can just be an option of the same text slot. In this screenshot, you can see that we allow you to switch between different types of slideshows. Make sure you try that out in the demo. It is probably our favorite new feature. We really sweated the details on making sure the option control was contextual. We hope you appreciate the effort.

There are many other new features and highlights, but for the moment I will leave you to find them in the demo (remember: user is “admin” and password is “demo”) or in the documentation. (We promise to highlight these in future posts.)

So, what does this mean to you?

Well, it depends. If you are a PHP developer with Symfony skills you can get started today. From our README:

Right now Apostrophe is best suited to PHP developers who want to make an intuitive content management system available to their clients. Apostrophe is very easy for your clients to edit, administer and maintain once it is set up. Right now, though, Apostrophe installations does call for some command line skills and a willingness to learn about Symfony. We are working to reduce the learning curve.

If you are a front-end developer and want to get started using Apostrophe, talk to us. We are in the process of working out a package where we set up a staging server with Symfony and Apostrophe running on it. We would train you on templating in Apostrophe and you should be up in running in a day or two.

If you don’t want to go that route, here is what we suggest:

Front-end developers who do not yet have PHP and Symfony skills but wish to set up an Apostrophe site by themselves should consider tackling the Symfony tutorial to get up to speed. It’s not necessary to complete the entire tutorial, but it helps to have at least a passing familiarity with Symfony.

If you just think Apostrophe is rad and you want one… like now, just drop us a line. We would be happy to design and implement an Apostrophe site for you. You would be joining some good company if you do.

Surprise!

We (more accurately Tom) decided to build an extra slot last night as a gift for making you wait an extra day. Isn’t that nice of us (him)?

If you are observant you may have noticed an extra slot in the screenshot above. So without further ado, we present the Feed Slot (commonly referred to as the RSS Feed slot, but it will take Atom feeds as well). Use this to bring in your Twitter updates or maybe our Apostrophe SVN code commit feed.

Feel free to thank us anytime. (We like expensive beer.)

This is really just the beginning. We hope you have an opportunity to check out Apostrophe. We would love to hear from you if you do. Comments below would be much appreciated (and read), as well.
__________________

Don’t forget to follow us on Twitter for on-going updates: @apostrophenow

If you are a developer, the Apostrophe Trac is the home of the open source community. On that site you can open support tickets, browse and contribute to the Wiki, and access and potentially contribute to the source code via svn (you’ll need to contact us if you want write access).

Also, please join the Apostrophe Google Group if you want to tap into the community of people using Apostrophe to get support and help.

Oh So Close!

February 10th, 2010 by Geoff 2 Comments

We have decided to push back the release of Apostrophe 1.0 until tomorrow.

We are truly in the home stretch. Just hitting a few bugs, finishing up documentation and adding some instructional content to the demo site. To tide you over, we are publishing this screencast of how you add video to a project by searching YouTube from within Apostrophe. Note how we bring in associated metadata (url, title, etc). For the record, you can add video by pasting in embed codes from countless other services like Viddler and Vimeo.

Please tune back in tomorrow.

P.S. We are not blaming the snow for the delay, but did want to note that we are certainly under a deep white blanket here in Philadelphia.

punkave.com is way cooler now!

December 23rd, 2009 by Rick 1 Comment

Not to toot our horn or nothin, but we’ve just launched a new site for ourselves. At 6:05pm on the last business day of the year we’ve cobbled our children some new shoes. It was a lot of fun making Apostrophe flex a little to suit our own needs. We figured it was time to drink our own koolaid. And it’s almost fully debugged (degrades gracefully) in IE.

So go check out our shiny new site!

To Geoff, Alex, John, Tom, (and if you didn’t know we’ve recently expanded to include) Dan, and Jake:

cheers

Cheers bros! It’s been a wonderful year.