473,231 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

When does assigning variables become more efficient than $_POST

This may not be a big deal, but I'm just kinda curious. If I have a
page that submits a form to itself, when is it better to assign each
element in $_POST to a variable to use for the rest of the page?

My situation probably doesn't make a difference, but say I have about
10 form fields, and when the page is posted back to itself, i call
each of those form fields 2 times (1 for error checking, 1 for SQL
insert, or to pre-fill form).

So where does it become more efficient to only call $_POST once and
assign those to variables? Do you use the variables if they are
needed any more than one time?

Thanks for you thoughts!
Jul 16 '05 #1
1 2814
On 11 Jul 2003 14:35:43 -0700, sc******@cableone.net (dSchwartz) wrote:
This may not be a big deal,
It isn't. :-0
but I'm just kinda curious. If I have a
page that submits a form to itself, when is it better to assign each
element in $_POST to a variable to use for the rest of the page?

My situation probably doesn't make a difference, but say I have about
10 form fields, and when the page is posted back to itself, i call
each of those form fields 2 times (1 for error checking, 1 for SQL
insert, or to pre-fill form).

So where does it become more efficient to only call $_POST once and
assign those to variables? Do you use the variables if they are
needed any more than one time?


If you're bothered about it, benchmark it.

<pre>
<?php
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();
for ($i=0; $i<100000; $i++) {
$dummy = $_GET['x'];
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Using \$_GET: $time seconds";

print "\n";

$value = $_GET['x'];

$time_start = getmicrotime();
for ($i=0; $i<100000; $i++) {
$dummy = $x;
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Using variable: $time seconds";

?>
</pre>

On my creaky old P200 Linux server this comes out with:

Using $_GET: 1.2699910402298 seconds
Using variable: 1.0599220991135 seconds

That's if you use the value 100,000 times, this saves a grand total of just
over 0.2 seconds.

But what are the odds of you using a form variable that many times? And it's
almost certain you can get speed increases of many orders of magnitude greater
by improving your algorithms rather than shaving milliseconds off by avoiding
array access.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Powell | last post by:
// CLIENT GLOBAL FUNCTION TO PARSE $_SESSION IF 'tempIDArray' IS SET function parseTempIDArraySession() { $tempIDArray = $_SESSION; $_GET = $_SESSION]; // RESET $_GET WITH SESSION ARRAY...
7
by: juglesh | last post by:
<body><div align="center"> <?php if (!isset($password)){ ?><form action="<?php $_SERVER; ?>" method="post"> type password here&nbsp;<input name="password" type="text" size="8"> then <input...
8
by: Ian Davies | last post by:
Hello I am trying to run a few INSERT queries only if the user clicks 'continue' in a <a href> The queries takes variables created from SELECT queries. I have tried to acheive this by putting The...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
9
by: Simon | last post by:
Hi, I have written an ActiveX object to resize images and upload them to a database, this all works fine but when I close internet explorer the process iexporer.exe is still running in my task...
3
by: Taras_96 | last post by:
Hi everyone, I've got a rather unconventional architecture that I'm having problems with... I have a form called "searchForm", that has an input of type "submit" (with name = "submitButton...
26
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set...
8
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I have a large class with a lot of member variables. I also have a function in the class that I would like to change ALL Of the member variables. I am trying to assign...
1
by: joshai | last post by:
Hi, I'm pretty new to the php/mysql world and am building an article database for a website with multiple content types. I have an entry screen built that allows the site owner to enter articles,...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.