NYCPHP Meetup

NYPHP.org

[nycphp-talk] POSTDATA and back/resubmit revisited

Chris Shiflett shiflett at php.net
Mon Jun 11 13:32:06 EDT 2007


Cliff Hirsch wrote:
> > 1. Why is there any duplicate processing?
>
> A Form submission would start by running the front-end controller,
> which loads a whole lot of classes, checks authentication,
> establishes the DB connection, inits sessions, sets up the template
> controller, and other housekeeping chores.

This sounds like an argument against using a framework. :-)

Jesting aside, if you accept this overhead for every request, why would
it suddenly be unacceptable for a request to process a form?

You incur this overhead twice, but if adding a request / response
transaction noticeably degrades the performance of your web site, I
would speculate that your problems have little to nothing to do with
whether you use this particular technique.

> > 2. What is the basis of your concern regarding session overhead?
> > You can persist data in cookies, if it's really a concern.
>
> This probably dates back to a presentation at the Zend conference
> several years ago given by Joyce from Renkoo regarding the evils of
> sessions.

She might have been speaking about scalability. As your userbase
increases, server-side session data stores become increasingly difficult
to scale, although solutions like memcache make this problem manageable
for lots of really popular sites.

An alternative is to use cookies as your session data store, but then
you have to incur extra processing overhead, because you need to take
steps to ensure that you can detect any attempt to tamper with the cookies.

> But I use them, so what's another few fields.

In that case, the overheard of fetching session data is an expense you
already incur.

> > 3. What is a thanks redirect, and why must it grab data again?
>
> By this I meant the page following a form submission. Say the form
> did something as simple as store a record in a DB. Now if we
> redirect, and want to say, "hey thanks for submitting this data", we
> need to query the DB to retrieve it.

You're already using sessions, so you can persist data for free.

By the way, since writing the article, this technique has been described
as a design pattern called PRG (POST, Request, GET).

Hope that helps.

Chris

-- 
Chris Shiflett
http://shiflett.org/



More information about the talk mailing list