Best practice PHP Form Action
Posted
by Rob
on Stack Overflow
See other posts from Stack Overflow
or by Rob
Published on 2010-04-10T10:02:57Z
Indexed on
2010/04/10
10:13 UTC
Read the original article
Hit count: 320
Hi there i've built a new script (from scratch not a CMS) and i've done alot of work on reducing memory usage and the time it takes for the page to be displayed (caching HTML etc)
There's one thing that i'm not sure about though. Take a simple example of an article with a comments section.
If the comment form posts to another page that then redirects back to the article page I won't have the problem of people clicking refresh and resending the information.
However if I do it that way, I have to load up my script twice use twice as much memory and it takes twice as long whilst i'm still only displaying the page once.
Here's an example from my load log. The first load of the article is from the cache, the second rebuilds the page after the comment is posted.
Example 1
0 queries using 650856 bytes of memory in 0.018667 - domain.com/article/1/my_article.html
9 queries using 1325723 bytes of memory in 0.075825 - domain.com/article/1/my_article/newcomment.html
0 queries using 650856 bytes of memory in 0.029449 - domain.com/article/1/my_article.html
Example 2
0 queries using 650856 bytes of memory in 0.023526 - domain.com/article/1/my_article.html
9 queries using 1659096 bytes of memory in 0.060032 - domain.com/article/1/my_article.html
Obviously the time fluctuates so you can't really compare that. But as you can see with the first method I use more memory and it takes longer to load.
BUT the first method avoides the refresh problem.
Does anyone have any suggestions for the best approach or for alternative ways to avoid the extra load (admittadely minimal but i'd still like to avoid it) whilst also avoiding the refresh problem?
© Stack Overflow or respective owner