For the past few months, I’ve been using Ajax for purely UX purposes, i.e., allowing the user to submit forms, access content, etc, without having to reload or navigate away from the page. But, after reading an article about the benefits of using Node.js, I started thinking more about whether or not my application could benefit from submitting micro-requests to the server instead of, for instance, submitting the data from a giant form at once.
Now, the way my application works is my DomainObjects map pretty directly to both my db tables and also the forms in the view layer. So, for example,
class Demographics extends DomainObject {
protected $first;
protected $last;
protected $middle;
protected $ssn;
// getter, setter methods
}
would have a form that contains inputs for all of the settable properties for the user to update. So, by this point, we have a Demographics object that holds the information for a person in my db. Well, currently, when the user updates the person’s information, the Demographics object is recreated using the data from the page (I’m hiding the customerID in the HTML and using it to re-instantiate the object), but now I’m wondering if this is 1. necessary and 2. good practice.
So, my main question is this: if I do decide to submit micro-requests via Ajax, would I actually need to re-instantiate the objects, or is there some sort of “thread” that keeps my PHP alive in between requests? (i.e., are previously instantiated objects accessible?).
Also, is this practice of recreating the DomainObject and hiding the row’s ID in the HTML common practice, or should this be avoided?
Every request cycle is its own thread, and that’s as it should be. You don’t want to have several different users sharing the same data. This looks a perfect example of a piece of data that should be stored in a database and retrieved on each request. However, your micro-Ajax request approach sounds like a good idea otherwise; each request could talk to a different table in the database and possibly a different URL entirely, and progress would be stored and recreated each time in the DB.
As for your second question, I’d need to see some code to know what you’re trying to accomplish.