Drupal Planet

Using HTTPRL for Parallelization: PHP Multitasking Without Forking With stream_select()

Posted by Droplabs on May 12, 2012 at 11:34pm

Did you know that PHP comes with a very powerful function called stream_select()? In short it's a wrapper for the select() system call. This allows for synchronous I/O multiplexing, or in sudo-code, a way to read multiple input/output streams without blocking; only selecting streams that are ready for I/O. In English this means that you can do parallel work from a single PHP thread without forking (forking a process is slow and complex in PHP).

In this talk at the High Performance Drupal meetup at Droplabs on May 1, 2012, Mike Carper (@mcarper) went over some code called the HTTP Parallel Request & Threading Library — or HTTPRL in short. Using PHP's stream_select() HTTPRL can send http requests out in parallel. These requests can be made in a blocking or non-blocking way. Blocking will wait for the HTTP response; Non-Blocking will close the connection not waiting for the response back. Non-Blocking requests are what make this better in comparison to cURL, better control over redirects is the other reason.

This talk was recently given as PHP Multitasking Without Forking at LinuxFest Northwest 2012 and the topic is further described by cotto in the High Performance group at http://groups.drupal.org/node/226054

Video: http://blip.tv/ladrupal/episode/6128019  
Comments: http://groups.drupal.org/node/223324#comments  

Tags:

Examples of returning database query results as CSV

Posted by Coder in the Rye on May 12, 2012 at 11:04pm

Have you ever needed a comma-separated list of node ids from your database to put into a query in another Drupal site? Or just for testing?

Before we get started, I should note, I was really happy with drupal.org today. I came back after a couple weeks of work stealing me away, and found 4 issues I was subscribed to or involved in that had patches reviewed and committed. Even some of my own! What a great feeling. So surely, I wanted to give back by reviewing some patches in my own queue.

So, I went about resolving a couple issues with the 7.x release of the Delete All module. At some point, I wanted to get a list of nids in a comma separated value form in order to put them in a sub-query. I'm a command line junkie (in the sense that I'm addicted to it, not necessarily that I know the right way to use it).

Now, if I wrote out some PHP code along with drush to run it so I get use of Drupal functionality, then I could simply do:

$> vim getnodes.php


<?php
$result = db_select('node','n')->fields('n',array('nid'))->condition('type','page','=')->execute()->fetchCol('nid');
print_r(implode(',',$result));

$> drush php-script getnodes.php

An even easier proposal is just running the above, but directly using drush sql-query

$> drush sql-query "select nid from node where type='page';"

But then you still need to pass it to some php code or something to get csv values.

But what if I want to get this same info directly from the MySQL database. Well, one way is selecting into an OUTFILE as part of your query.


SELECT nid
INTO OUTFILE '/tmp/nodes.csv'
FROM drupal.node WHERE type = 'page';

There are several problems here. For one, you need access to write files on the machine, which is not always the case. Plus, with AppArmor in Ubuntu, you sometimes can't do this at all without disabling it. Two, you have to go find the outfile and open it afterwards to get your data (though perhaps that could be piped as well, though you would still have the permissions problem). Three, it requires writing your queries differently, and I can never get used to putting "INTO OUTFILE '/tmp/whatever.csv' in the right place in the query. Fourth, you have to specify how to enclose all the fields and not put new lines, etc.

But hold on! There's a better solution. One can do this in a couple of piped commands directly from the command line. A lot of googling couldn't find this solution in its entirety but this is pulled from a couple of StackOverflow posts plus some advice from a blog.


mysql -uuser -p -h myhost.com -A drupal_cms -e "select nid from node where type='page'" | awk '{print $1","$2'} | tr -d '\n'

Or if you have drush available:

drush sql-query "select nid from node where type='page'" | awk '{print $1","$2'} | tr -d '\n'

This uses the ability to run a MySQL query from the command line and then pass it to awk to have the results separated by commas, then finally on to the truncate command, making sure to use -d, which removes the new lines. And Voila, we can start running these commands easily from the command line and get on with our business faster. Put this as a function in your .bash_profile


function mycmscsv() {
mysql -uuser -p -A drupal_cms -e" $@ " | awk '{print $1","$2'} | tr -d '\n'
}

And now all you have to do is run mycmscsv "select nid from node where type='fellows_blog_post'"

Hope you found that useful, and if you have a better way to do it, let me know!

If you liked the above, then you may like the Bash Cookbook: Bash Cookbook: Solutions and Examples for Bash Users (Cookbooks (O'Reilly))

Tags: Drupal Planet

DrupalCamp Göthenburg 2012

Posted by Morten.dk on May 12, 2012 at 8:51pm

Apparently my reputation is not as bad as i have feared!

read more

Value Added Tax?

Posted by Cafuego on May 12, 2012 at 4:32am
Could it be? No! Never!

A few weeks ago I saw a tweet by the Drupal Assciation asking for feedback on, amongst other things, how it could make being a DA member more attractive. The survey appears to still be open, so if nothing else please go fill it out.

However, before you do so I would draw your attention to question 15:

How much would the following benefits interest you in becoming a Member (or renewing your Membership)?

and in particular one of the options listed there:

"Discounts on software (e.g., something like Adobe)"

When I read that I was flabberghasted. That would effectively mean the Drupal Association subsidising a proprietary software company, helping them to expand their market share. That's not why I use and support an open source project. In fact, I use and support open source software for the completely opposite reason!

Ah, I hear you say, but the Drupal Association has no control over the software project, so this doesn't matter. I beg to disagree. I think this would send a strong signal that the open source philosophy isn't actually an important part of Drupal.

I am amongst the first to admit that there may be a place for proprietary products in the world. In fact, I have an iPhone, which is a completely closed and proprietary device. Some (though not all) designers probably have perfectly valid reasons for needing to use Adobe's software.

However, I very much don't want to be part of an organisation or project that would support these proprietary software companies by providing them with extra sales. Especially not companies that try to sting their customers for as much money as they possibly can.

ps: The attached image was inexpertly created using The Gimp. Both I and it can do much better when not rushed ;-)

Sublime Text 2 plugin for Drupal

Posted by tanc.me on May 12, 2012 at 1:03am

I had previously created a simple Drush based script to recursively scan a Drupal project and create a Sublime Text 2 autocompletions file from all functions the scan found. Unfortunately this file was not unique to each project and needed to be generated each time anything changed. So I wanted to get around the problem by creating a plugin which leverages the ST2 API.

The plugin uses the on_query_completions method of the ST2 API to inject a project specific JSON array of completions. This array is generated each time a file is saved by scanning up the project tree until a Sublime Text project file is found where it then recursively scans each .module, .inc and .php file for functions and assembles a JSON formatted completions file. This completions file is stored alongside your ST2 project file.

For this plugin to work you must save your ST2 project file in the root of your Drupal project (at the same level as index.php, CHANGELOG.txt etc). You will also want to exclude the completions file from any VCS you use. In git you could add the following to your gitignore file:
*.sublime-projectcompletions

As I have an SSD based computer the completions file is generated very quickly and using threading there is no noticeable loss of speed in ST2 while it generates. I haven’t tested on non SSD enabled machines so some feedback would be very useful. If anyone with better Python skills than me can optimise the code or offer solutions I’d be very grateful.

The plugin has been submitted to ST2’s excellent package control repository. From there it should be easy to install but until it appears you can also manually install it from github: https://github.com/tanc/st2-drupal-autocomplete.

Drupal 6 Ubercart Theme Add to Cart Form

Posted by Code Karate on May 11, 2012 at 11:37pm

So you need to theme the Add to cart form that is output by Ubercart? If so, read on for more information. If you are looking to change the general theme or style of the Ubercart product node page, then you might want to look at my post on theming Ubercart Product Page for Drupal 6.

Post Topics:  Drupal Drupal 6 Ubercart Drupal Planet

read more

Drush 5.1 and SSH Tunnels

Posted by Pantheon Systems on May 11, 2012 at 9:02pm

We're happy to announce that we've updated the bundled version of Drush on Pantheon to 5.1. With the accompanying update to our drush.in SSH gateway, we've also added much better support for interactive commands — including the much-beloved sql-cli, which allows you to access mysql directly. You can find instructions on running Drush on Pantheon in our helpdesk.

We have also improved drush.in to allow you to create SSH tunnels. This is an advanced feature: it's good right now for customers who want to access their database or Redis cache over an encrypted channel, and will be another good piece in the Pantheon toolbelt going forward. Copy/paste instructions for setting up tunnels will be added to the dashboard soon, but for those who are already savvy the mechanism is straightforward.

Every site on pantheon has a UUID (unique id) which you can find in your dashboard url or other places. Targeting the right service in the right environment is a matter of combining this with the UUID. For instance, suppose I had a site ID of 311d8ef5-4fc8-4bd2-8644-6c842f3f1941, I would use domains like:

  • dbserver.dev.311d8ef5-4fc8-4bd2-8644-6c842f3f1941.drush.in for the development environment database
  • cacheserver.test.311d8ef5-4fc8-4bd2-8644-6c842f3f1941.drush.in for the test environment cache

You can find the proper ports to tunnel into (as well as the authentication information you need to use your client) in the mysql connection screen. There's more information on making tunnels in the helpdesk.

We're always improving Pantheon with additional features and functionality. Let us know what else you'd like to see by posting an "Idea" on our community support site.

Future Insights Recap

Posted by Chapter Three on May 11, 2012 at 8:33pm

Last week I attended the Future Insights Conference in Las Vegas. For those unfamiliar with this conference, it's a combination of the Future of Web Design conference and the Future of Web Apps conference. It was the best conference I've ever attended with five days of amazing speakers who shared information spanning from SEO best practices, to responsive design trends, to how to run a company where your employees are truly happy. Here are some of the highlights and take aways.

Creating Better UX

  • Eliminate "rights of passage"
  • UX is about psychology, and neuroscience, and linguistics and in short, understanding humans
  • Be empathetic to your users
  • Respect user efforts
  • We have strong emotional reactions to things that don’t work
  • Using warning signs is not a design solution
  • If you need loads of instructions, then something is not intuitive

Deisgn

  • Design is about saying no
  • When you design for everyone, you design for no one
  • Design is not a democracy
  • Design is about making hard decisions
  • Great design IS your business plan

Client Centric Web Design

Term coined by Paul Boag
  • Sending clients away happy is a fundamental part of our job
  • The client must be involved
  • User centric design exists only to serve client centric design
  • User needs are massively important, but only in the benefit they bring the business
  • Respect must go both ways
  • If your client has a good idea, tell them so and explain why it’s good
  • Don’t only rely on digital communication
  • Be patient
  • Explain what will be next
  • Identify roles
  • It’s the client’s job to identify the problem
  • It’s our job to provide a solution
  • Site other experts in your field to back up your statements

SEO and Social Media

  • Google+ is giving away traffic. Use it.
  • Be an early adopter
  • Track links your users share
  • Always respond to comments on Twitter and Facebook
  • RSS is great for SEO

SEO General Best Practices

  • Responsive design is good for SEO
  • Know what search words people are using to find your service and use those words in your site's content
  • Avoid duplicate content
  • Google’s Panda update lowered ranking of sites with “thin” content
  • Google gets confused by microsites or content on 3rd party domains. Keep all content on one site when possible

Creating Amazing Companies

  • The difference between good and great companies is strong company culture
  • Values define this culture
  • Great companies have a higher purpose
  • Define your company's design principles

Adaptive Content

  • COPE (Create Once, Publish Everywhere)
  • Multiple sizes
  • Meaningful metadata
  • Written for reuse
  • Content must be reformatted into chunks, rather than blobs
  • Defining those chunks will take analyzing character counts and retraining our users on how to recreate content
  • Divorce the display from the content itself

Reading List Suggestions

Sites Worth Checking Out

Responsive web design off the shelf with Panopoly

Posted by Victor Kane on May 11, 2012 at 4:49pm

I've recently blogged enthusiastically about Panopoly in the context of a simpler, lower cost and more “share the wealth” democratic path to powerhouse Drupal web app development emerging from the recent Denver DrupalCon 2012. And I've promised to write a series of articles on “using Panopoly as a starter kit for the rest of us” in the context of a responsive process and the creation of a responsive user experience. Well, with the recent release of Panopoly 7.x-1.0-beta3, there's no time like the present to write the kick-off article.

So together with my fellow AWebFactory web developer compañero martindido (Martín Di Doménico) we installed the new beta3 version and here share our findings:

read more

The Power of Maps and Drupal 7

Posted by Mediacurrent on May 11, 2012 at 12:28pm

Maps can be a powerful tool for sharing information.

A well built map can make data and ideas accessible to people in a way that is not always easy to do in words. Most of us use maps on our phones and in our cars to help us get around. What you don’t see everyday are maps being used to share dense amounts of information in easily accessible and highly informative ways. Maps can tell a story, or help influence the way we think, even motivate us to help with a cause.

Form in Block – a hack for getting node/add forms into solr search results

Posted by Drupalpress, Drupal in the Health Sciences Library at UVA on May 11, 2012 at 11:41am

Use Case: We want patrons to find our forms easily.  If they need help finding something they should be able to go to a search bar, type in “consultation request”  and get to our consultation request form.

The Challenge:  First off Solr doesn’t index the node/add/your-content-type-here pages by default – I’m certain there’s some workaround, however it’s not obvious (dear readers are welcome to retort).  Secondly none of the form results should be indexed by solr in the first place – we certainly don’t need our patron’s requests showing up anywhere ever.

The Hack: Form Block allows you to make content types available as blocks.  Pretty straightforward, click a few buttons, go to the context editor, and woo-ha = forms in a block = we took the pages that were already returning for the queries we were interested in and just added the form to those pages.

Here’s the VERY brief overview – 1:30 seconds or so worth http://www.youtube.com/watch?v=gzvq-t1m03A that goes over turning a content type into a block as well as adding the block to a context using the context editor that comes with the admin toolbar

Form Block settings in content type

Form Block settings in content type

Now is also a good time to mention that if you are using context’s the Admin toolbar is almost required – it really extends the UI giving you a drag and drop interface for your blocks within every context active on a given page.

Adding node form in the context editor

Adding node form in the context editor

Form Nodes in context Editor

Form Nodes in context Editor

A form in a block!

A form in a block!

12 hours to go

Posted by DrupalCon Munich on May 11, 2012 at 7:12am

At the time of me writing this, there is a little over 12 hours to go. 12 Hours for anybody who wants to, but has not yet, submitted a session proposal. 222 Sessions have been proposed up to now and all tracks appear evenly served. Tonight Friday, May 11th at 24:00h, Munich Time, someone will manually remove the option to submit session proposals and the track chairs begin their jobs to study al proposals in their respective tracks this weekend.

So hurry
If you want your session to be considered you may want to hurry up. Make sure your proposal fits the requirements published on this site. If you have any issues, questions, or need for assistance, do, by all means, get in touch with the respective track chair. They can and will help.

I am looking forward to your comments to this blog and many more proposals in the next 12 hours...

The Mechanism
Please recall from my earlier blog that we have changed the selection process. I thank all of you for the positive feedback. No more voting but you have a very efficient way to get yourself heard. Work allong the track chairs and study the session proposals AND LEAVE YOUR COMMENTS! This will help the track chairs decide and will also help the presenter with his/her preparations for the session.

Cheers

Jos

ps: Spread the word. Tell others that time is running out and they need to get things moving if they want their sessions submitted.

Drupalcon Content Sessions Tracks

Gymnastics, 3000 BC, Munich and Drupal

Posted by Matthew Saunders on May 11, 2012 at 1:47am

Drupalcon MunichHere we go again! Drupalcon Munich is just around the corner - August 20 - 24th. That may seem like a long time, but for a veteran of organizing one of these events, I can tell you that the work is ramping up rapidly. All my best to our friends and colleagues over the pond who are, undoubtably, working like crazy. I'm looking forward to enjoying the next convention not being behind the scenes.

Agile Gymnastics and Timebox Tumbling - A Hybrid Approach

Over the last few months I've presented on Agile Scrum twice. Once, as one of the Drupalcamp Austin Keynotes and a second time at Drupalcon Denver with my good friend Stacey Harrison. The presentation evolved from one of the events to the next. I've continued to wear my presenter hat and am ready to do Mark III on the topic of Hybrid Agile Project Management.

Learn from the experiences of Examiner.com's team. We've done it all - cowboy, waterfall, extreme, and agile scrum.

Learn why...

  • Waterfall doesn't always work
  • Agile has a place, but isn't the holy grail
  • Cowboy can kill the relationships you have with your stakeholders
  • How "Fixed Scope" is a lie
  • That a combination of approaches is the answer
  • The Examiner team has carefully honed, updated, improved, and iterated its process for over two years. It continues to evolve, improve, and make development more consistent and predictable.

read more

Addison Berry and Sally Young at Drupal Sprint i København

Posted by Lullabot on May 10, 2012 at 9:06pm

Addison Berry and Sally Young will be attending Drupal Sprint i København in Copenhagen on May 12 to participate in a core issue sprint and discuss the Learn Drupal ladder. If you're in the area, stop by and join in!

Date(s):  May 11, 2012 - 11:00pm

Drupal Voices 227: Florian Loretan talks about DrupalCon Munich

Posted by Lullabot on May 10, 2012 at 8:00pm

Florian Lorétan, one of co-leads for DrupalCon Munich, takes a moment to discuss what is happening with the upcoming conference and what people can expect. He introduces the overall theme "Open Up! Connecting Systems and People" and explains what it means, how it will tie in to the sessions, and why it's important.

This Drupal Voices was recorded at the 2012 DrupalCon in Denver.

Release Date: May 10, 2012 - 3:00pm Album: Drupal Voices Length: 5:12 minutes (3.61 MB) Format: mono 44kHz 97Kbps (vbr)

What day of the week should the biweekly Mobile Initiative IRC meeting be held?

Posted by Drupal 8 Initiatives on May 10, 2012 at 5:00pm
Monday 0% (0 votes) Tuesday 0% (0 votes) Wednesday 0% (0 votes) Total votes: 0

Mo betta form UI with Jammer and StringOverrides

Posted by Drupalpress, Drupal in the Health Sciences Library at UVA on May 10, 2012 at 4:37pm

Use case: Our patrons don’t really think of “saving” their class signups, nor do they often care to preview the request form that they recently filled in.

Quick solution: Using Jammer (admin/settings/jammer) we are able to easily remove the preview (delete, or submit) button on selected content types.  This is also a place to remove path, menu, author and several other fields.

Jammer - remove preview

Jammer - remove preview

Saving makes sense for admins, however our patrons really don’t think of saving their work – they’re submitting requests. Making a happier UI is part of the work we do to keep our patrons around, so we use more vernacular terms to mo betta stuff.  The obvious limitation here is that it overrides EVERY string rendered

Simple string overrides simplify succinctly

Simple string overrides simplify succinctly

in drupal (not in the content, of course)

If anyone knows of a module that’ll let us customize buttons on a per content basis please chime in – not interested in writing tpl.php’s for every one of these though – it’s just not that big a deal yet. Speaking of UI thanks Vid @ the University of Oregon (rss added to the left here) for their work with Taxonomy Super Select Styling http://pages.uoregon.edu/vid/2011/01/21/put-taxonomy-super-select-check-boxes-into-1-2-or-3-columns/

Impending Drupal Site Launch? Use the List

Posted by Zivtech on May 10, 2012 at 4:35pm

After months of site development, code, more code, and long hours, launch day arrives. A site launch can come as a relief, create a bittersweet moment, or one filled with pride and a sense of accomplishment, not unlike a parent sending a child off to their first day of kindergarten.

read more

Setting up SSL Offloading (Termination) on an F5 Big-IP Load Balancer

Posted by Lullabot on May 10, 2012 at 12:00am
Hardware-based SSL decryption allows web servers (Apache, nginx, Varnish) to focus on serving content.

At Lullabot several of our clients have invested in powerful (but incredibly expensive) F5 Big-IP Load Balancers. One of the primary reasons for investing in an F5 is for the purpose of SSL Offloading, that is, converting external HTTPS traffic into normal HTTP traffic so that your web servers don't need to do the work themselves. HTTPS requests (and more specifically, the SSL handshaking to start the connection) is incredibly expensive, often on the magnitude of at least 10 times slower than normal HTTP requests.

In a quick, largely unscientific test, here are two Apache Bench results against a stock Apache install, one with SSL and one without. Just serving up a static text file:

ab -c 100 -n 100 http://localhost/EXAMPLE.txt
Requests per second:    611.21 [#/sec] (mean)
Time per request:       163.609 [ms] (mean)
Time per request:       1.636 [ms] (mean, across all concurrent requests)
Transfer rate:          816.54 [Kbytes/sec] received

ab -c 100 -n 100 https://localhost/EXAMPLE.txt
Requests per second:    48.52 [#/sec] (mean)
Time per request:       2060.857 [ms] (mean)
Time per request:       20.609 [ms] (mean, across all concurrent requests)
Transfer rate:          64.82 [Kbytes/sec] received

Drupal 6 Override views pager theme function

Posted by Code Karate on May 9, 2012 at 9:12pm

It is possible to override a specific pager for a specific views using a theme function in your template.php file. Here are the steps needed:

Theme Views Pager Step 1

No matter how you want your pager to look, make sure to select mini pager within views. This will allow you to take advantage of the views pager theme hook patterns. I was unable to get this to easily work when using the full pager.

Depending on how you want your pager to look, you can start with either the code that produces the views mini pager or views full pager using the options below.

Post Topics:  Drupal Drupal 6 Views Drupal Planet

read more

Subscribe with RSS Syndicate content

Planet Drupal aggregates broadly appealing, Drupal-related blog posts pertaining to the community at large (code, advocacy, marketing, infrastructure etc.). If you would like your blog to be included in the Planet, read the requirements and steps on how to join.

Collecting posts from the following 470 sources:

XML feed
nobody click here