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.

21 comments on Persistant stack class for PHP

  1. Russian women (not verified)
    Tue, 2010-06-15 17:33

    You have done the big and useful work.
    Thanks for the information.

  2. Anonymous (not verified)
    Tue, 2010-05-25 08:36
  3. Air Jordans 1 (not verified)
    Fri, 2010-04-23 08:04

    The white/black-red and black/red Jordan I was released as a retro in 1994 and sold very poorly,Air Jordan 1, however in 2001 they released them again in patent leather and the demand was much greater. Jordan Retro 1,Despite the changing of the times, Air Jordans 1,the Air Jordan line has managed to survive controversy and changes in fashion while producing a quality basketball shoe.

  4. Freestyle medela (not verified)
    Sun, 2010-04-04 15:33

    You have been doing a great job, just keep impressing like this, I am going to bookmark it right away!
    Chris Harris
    Freestyle Medela

  5. Sandy (not verified)
    Sat, 2010-04-03 03:33

    There are many interesting views in your post.
    You have presented indeed creative inputs.
    Im sure that anyone would like reading this.
    A well written blog always catches attention.
    Well, thanks again for sharing this great work.
    I hope to see more of your nice works here.
    I will certainly share this with my friends.

    Antioch Ca Foreclosures | Home For Sale 3.5% FHA Home For Sale | Hayward Ca Foreclosures 100% VA Concord Ca Foreclosures |

  6. Virtual Sex Games (not verified)
    Fri, 2010-03-26 10:45

    This was the nice script work I love it may be it will be useful for me.

    Thanks
    Virtual Sex Games

  7. Anonymous (not verified)
    Thu, 2010-03-25 03:11

    Good post, thank you for sharing.
    Ngan hang|Vay mua nha

  8. Oregon Winery (not verified)
    Tue, 2010-02-16 12:00

    Mike Cantelon? You an Asian my man? Your blog such amazing works.

  9. sanalburasi (not verified)
    Mon, 2010-02-15 14:53
  10. Anonymous (not verified)
    Thu, 2010-02-04 21:12

    for to play the enjoyable games; Çok Güzel Oyunlar, for the high quality photos Resimler Resimler Güzel Resimler and for the newest films; Online Film izle

  11. gucci shoes (not verified)
    Mon, 2010-01-18 03:00

    good

  12. miscel (not verified)
    Sat, 2010-05-08 20:44

    I had read this article. I thank you the one who wrote that. I had read some articles as this one. Moreover I had watched some videos that are similiar to them on izlesene. While i was watching some videos on facebook I had seen many videos about that.

    I thank the guy who wrote this article.

  13. Anonymous (not verified)
    Tue, 2010-05-25 08:35

    www.soodmall.com

  14. Anonymous (not verified)
    Tue, 2010-05-25 08:34

    www.soodmall.com

  • Eric (not verified)
    Thu, 2009-10-29 09:24

    i think your blog can be good base for essay help writing for students who need an essay

  • Freestyle medela (not verified)
    Tue, 2010-04-06 13:32

    you are really doing a great job, keep your posts like this one coming.
    Nicole Hogan
    Freestyle Medela

  • robert.killer (not verified)
    Tue, 2009-10-20 10:26

    Things newbies need to be aware of before doing this tutorial
    1.) The comments in the code snippets from the po files are *NOT* legal comments. The comment delimiter for po files afaict is "#:", maybe with a required leading unix newline. Do *not* use the shown "//" at the beginning of a comment line!
    2.) There is no explaination given why localisation names diverge so much, even vertically across the stack (zh_cn vs. zh-cn or en_us vs. JN0-522 eng or deu vs. de_de) The default application stack lacks consitency here, newbies need to be aware of that and establish their own conventions if the need arises.
    3.) The tutorial mostly just offers codesnippets and hardly says where to put what - newbies will have to look up the Cake filename/classdirectory convetions. As this tutorial is for 1.2 but the manual only covers 1.1 (as of now Sebtember 2007) there are a few differences to expect.
    4.) Everything under /app/view/ (templates) uses '.ctp' as ending as of CakePHP version 1.2. NS0-163 Trying to figure out CakePHP templating standards using this tutorial and the manual can be confusing, keep the above in mind.
    5.) The 'en_gb.gif' files (presumably images of flags)
    don't exist within the framework and it isn't said where they belong.642-973 I presume studying the class(es) used to instance the $html object or studying the manual may bring some insight here.
    6.) Bottom line: This is NOT a tutorial for people who aren't safe in navigating around in unknow application frameworks and learning their methodologies. Nor is it for those who are easyly confused by object oriented concepts. The scarcity of detail information in this tutorial can only be met by doing own further research on CakePHP! ... However it does give a nice strategy for dealing with persistant internationalisation for those willing to dive into the details to get it working for their application.

  • csy211 (not verified)
    Tue, 2009-10-13 01:59

    and for a few moments they appeared to go quite mad. To the amazement of everybody three of them flung themselves upon Boxer. Boxer saw them coming and put out his great hoof, caught a dog in mid-air and pinned him to the ground. Aion kinahmetin2 yang

  • jesse (not verified)
    Tue, 2009-10-20 02:56

    Keep up the good work, and post more articles like the one you have posted above.

  • Sjan Evardsson (not verified)
    Mon, 2009-05-04 16:01

    Great idea, and an elegant execution. I don't know why I hadn't thought of using SQLite for this sort of thing in the past, as I have always crammed things into flat files and dealt with all of the read/write/lock issues that entails.

  • porno (not verified)
    Tue, 2009-10-27 02:07

    Your web site is really nice if we think the others
    I think you had worked about that web site, hardly.
    Like I see. Thank you for information tht i get.