9

We have an Ubercart website that handles large volumes of orders daily, processes them and runs other tasks like billing, delivery routing, and future order creation.

Some of these tasks are heavy and sometimes cause PHP to timeout. Is there a better way to run these tasks like through Drush or Batch API?

Speed is not necessarily a priority (although nice), but we want to avoid timeouts, which can sometimes cause issues with billing correctly and scheduling daily orders.

Is Drush script the better option, or Batch API? Are there any tutorials to make better use of both?

13

I would not suggest to use the batch API, simply for the fact that batch operations depend from the browser; if for any reason the browser crashes, or it loses the connection with the server, the batch operations will not terminate, or (worse) they will be hanging. In fact, to avoid PHP timeouts, the batch operations cause the browser to ping the batch page at intervals; that is what happens, whenever JavaScript code is involved, or not (in the later case, Drupal uses the refresh meta tag).

In these cases, Drush is probably a better choice; you can create a custom module that implements specific Drush commands, or simply add a command file in the directory Drush uses for its commands.

  • 2
    Additional to drush you could actually also use a queue to get multiple items runned at the same time. – Daniel Wehner May 12 '11 at 19:17
2

Also you may use custom PHP CLI script. Here is a simple example for drupal 7:

#!/usr/bin/php
<?php
echo "Ubercart tasks\n===================\n";

$_SERVER['HTTP_HOST']       = 'default';
$_SERVER['PHP_SELF']        = '/index.php';
$_SERVER['REMOTE_ADDR']     = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD']  = 'GET';
$_SERVER['QUERY_STRING']    = '';
$_SERVER['PHP_SELF']        = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//-------------------------------------------

// Place your code here
  • 4
    The issue here is that you're reinventing the wheel. Drush is the better choice since it will already do this kind of thing and the framework is already in place! – Chris Cohen Apr 21 '11 at 8:54
  • 1
    I don't like to install drush on all servers where I want to do something. – ya.teck Apr 21 '11 at 13:02
  • 2
    Is there a reason why? it's about as intensive as installing any other module. – user7 Apr 21 '11 at 17:16
  • I was doing it many times and I think this method a little easier. – ya.teck Apr 22 '11 at 12:45
1

I have a D6 Ubercart site that requires significant back-end processing for 'auto-generated digital products'. I handle this via:

  1. Purchase of one of these custom digital products causes a db table entry for 'products that need to be compiled.' In that db entry is a 'status' field.
  2. A BASH script is started from within Drupal that runs in the background. This script is 're-entrant', meaning it is aware of being invoked while running and adds the new work to any existing work yet to be completed.
  3. This BASH script increments the 'status' field in the Drupal database as a custom digital product is created, and finally an email notice is sent to the user with a download link for their completed custom product.

This is a somewhat similar solution to the one proposed by Xio, with the exception that this does not use a PHP CLI script, but BASH scripts invoked by PHP in Drupal to run in the background. Those BASH scripts access the Drupal database and advance the 'status' values of any products it is compiling and sending to customers. Plus, Drupal is able to see these status values and report back to the custmers where in the 'custom creation process' their purchases happen to be at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.