Drupal developer days 2012 part 2
This is the second blog about the sessions during the Drupal Developer Days in Barcelona on June 16 and 17. See here for part one.
There will be one more post dedicated to some sessions on performance, because there were a lot of those. Probably because Drupal is serving more and more big, hig traffic site.
Introducing Symfony2
This session of Claudio Beatrice was an introduction to Symfony2. As you may all know Drupal 8 will incorporate some basic Symfony2 components, so it is wise to get up to speed with this framework. As I said it was an introduction to the framework about what it is and what filosophy it adheres. So what is Symfony?
- A reusable set of standalone decoupled cohesive php5.3 components.
- A full-stack framework.
- A request/response framework around http specs.
- A promoter of best practices, standardization and interoperability.
- An awesome community.
And why should we use a framework as Symfony? Because it removes some of the old habits in programming with a new structured way of doing things. As Claudio said: Leave stupid alone! So avoid:
- Singletons
- Tight coupling
- Untestability
- Permature optimization
- In descriptive naming
- Duplication
Symfony can help us with this. It can make you solid:
- Single responsibility
- Open/closed
- Obelisk substitution
- Interface segregation
- Dependency inversion
So what parts of symfony are coming to Drupal 8 then? For now these ones are confirmed:
- Class loader
- Service container
- Event dispatcher
- HTTP foundation
- Http kernel
But Symfony is not the only new thing in Drupal 8. A few days ago Twig was committed to Drupal 8. And people are talking about Assetic and Doctrine so keep your eyes open for all the new stuff! You can find the slides here.
Drupal and nodejs - beyond chat
NodeJS is as everybody knows very cool and totally awesome. It's one of the most popular buzz words around now. So of course we want to use it with Drupal! But why do you want to do that? What would be a practical use case? Frederik Lassen showed some possibilities.
If you want to do things as:
- handling/pulling external data-sources efficiently, (feeds, "idling", network latency)
- big uploads / big (dynamic) downloads
- sending / receiving lots of emails (pubsub)
it might be better to not use PHP. NodeJS might be the better choice. But we love Drupal so we want to leverage all the tools and power we have with that. We need to find a way to use them together. There are some initiatives to integrate both but there is no finished solution yet. There is the nodejs.module on Drupal.org. This one is tightly scoped and focuses mainly on passing messages. Then there is the node-drupal module on github. This one “consumes” Drupal from NodeJS. The downside of this module in my opinion is that it does query directly on the MySQL database. And then there is the new dnode.module. This module is a sandbox project and leverages the dnode-rpc-protocol. It's lightweight and JSON-based.
Frederik showed what you can do with this module an example with downloading large private files in Drupal. PHP sucks at this because it is blocking during the download. You can avoid this by taking the following approach:
- big files in Drupal (managed private files)
- Drupal validates/authorizes request
- Drupal generates token (& "firms" it)
- pass token + data (file path etc.) to nodejs
- Drupal redirects to nodejs server w/ token
- nodejs validates token
- nodejs (manipulates &) pumps file
In that way you off-load the heavy downloading to NodeJS. The best part is, you can edit the image on the fly. Because NodeJS is streaming you can pass the image to ImageMagik and add a watermark on the fly, for example.
The cool thing about the dnode.module is that the configuration of the NodeJS servers is done in Drupal through arrays, and there is even drush integration.
Of course introducing NodeJS in the setup makes it a little more complex, but NodeJS is extremely simple and you can achieve a lot with only a few lines of code. Furthermore it's extensible. In the above example you could think of pausing downloads, throttling, callbacks on end of streams etc.
Another cool example was that of integrating third party data with subpub. He made a demo module that pushes IRC messages to a Drupal site, making a new node and showing a message to everyone on the site. The other way around worked as well. So making a new node on the side would push a message to the IRC channel. And this worked with Rules. Pretty cool. For code examples and more information see the slides.
It's stil in early development and there are challenges ahead. So if you're interested in NodeJS and Drupal keep an eye on the different projects.
Drupal Search and Solr Wizardry
This session was by Nick Veenhof and Matthias Hutterer about the Search API Solr module and the apachesolr module. Why are there two Solr modules on Drupal.org? And which one is better?
The thing is that the apachesolr module was there way before the Search API. This module was supported by Acquia and has a lot of Solr knowledge inside. For now only apachesolr module is supported by Acquia Search. Also a lot of performance optimization that is in the apachesolr module is not yet integrated in the Search API version. So for big, high performance sites (over 1.000.000 nodes) the old module is the only way to go. And there is no Drupal 6 version of Search API because it was build with the new architecture of Drupal 7 in mind.
But I like the new approach of Search API with pluggable back ends. I think it's a better architecture. And I think that is the general opinion in the community. Even Nick Veenhof, the maintainer of the apachesolr module said that in the long run Search API is the way to go.
The first thing that has to be done is make the schema.xml and solrconfig.xml of the two modules compatible. And there is already a sandbox project where work is done in that area. So no more rivalry between the two but joint forces. Yeah!
For an excellent overview of the two modules and the differences between them see the slides of the presentation.