Reply to comment

Persistant stack class for PHP

I made a simple class that provides a simple SQLite-based persistant FIFO stack class for PHP 5 (similar conceptually to Stack::Persistent in Perl).

A number of times I've written Drupal scripts that run out of memory while trying to process large amounts of nodes (changing taxonomy, etc.). Adding them to a persistant stack, then doing them in batches, is an easy way to remedy this.

Example usage:

// Open or create stack: if you don't specify a filename, 'stack.db' will be used
$stack = new PersistentStack('my_stuff.db');
 
// Add simple things to a named stack
$stack->push('clothes', 'socks');
$stack->push('clothes', 'pants');
 
// Add something complete to another named stack
$stack->push('books', array(
  'title'  => 'The Tin Drum',
  'author' => 'Gunter Grass'
));
 
// Output the top of a stack without removing it from the stack
print $stack->last('clothes');
 
// Retrieve the top of a stack, removing it from the stack
$last_item = $stack->pop('clothes');

Documentation and code at GitHub.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options


CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.