Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts

    Saving data across script executions

    So I have an imaginary share.php. Say 10 users are submitting data to that script - every time they submit their own data, they get the most recent submissions of others as their response.

    Now, this will happen very often, every couple of seconds at least. File IO is slow, so writing to a temporary file is terrible. Similarly, hitting a DB everytime feels very inefficient (though I suppose if the DB is smart, it'll keep the row in memory so I just suffer a few API calls but no real File IO or processing costs).

    I'm under the impression the mod_php keeps the same interpretter running for all script calls, so it seems reasonable that I should be able to modify the actual interpretter's state with data (or do the functional equivalent - perhaps some deliberately exposed "Global" object). I know that Java servlets are perfect for this, but I'm unfortunately limited to a PHP environment.

    Ultimately, is there any way in PHP to save data directly to the interpretter's state, so subsequent script executions can pull the data directly from memory and alter it themselves instead of relying on some indirect data storage mechanism?

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jkd
    Ultimately, is there any way in PHP to save data directly to the interpretter's state, so subsequent script executions can pull the data directly from memory and alter it themselves instead of relying on some indirect data storage mechanism?
    i don't think so, no.
    the biggest disappointment for me, when i started with PHP, is that there isn't something as an application-object. but to be honest: i never actually couldn't do something because this was missing.

    i would try using a db, because it's simple to set up a small testscript and db-table, so you shouldn't waste to much time on finding out if this sollution is performant enough.
    depending on the choosen db, you'll be able to use some optimalisations. if you for instance use mysql, then you can use the recordset-buffering feature to get faster returns.

    obviously, a db has more overhead then writing the data to and from a textfile, but using a db will give you more flexability (for selects, sorting, agregations, ...) and has a lower lock-level then using files. so i would first try a db-approach and only look for an alternative if the db realy is a noticable bottleneck.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mysql has a heap storage engine which could be useful...
    http://dev.mysql.com/doc/refman/5.0/...ge-engine.html
    Last edited by fci; 06-23-2006 at 02:03 PM.

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    you could use shared memory.. though its only practical for smaller amounts of data look at shmop

    I have seen this used in conjunction with a small standalone socket server which you could load as a resource (if you were bored enough to write one )
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Both the Heap/Memory MySQL feature and the shmop (*excellent* name, btw) seem to be about as close as I'm going to get. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •