performance hit using $_GET[]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CorpDirect
Forum Newbie
Posts: 6
Joined: Mon Nov 14, 2005 4:17 pm

performance hit using $_GET[]

Post by CorpDirect »

My first attempt at using PHP to do something cool -- dynamically generate a PDF report using SQL data -- was pretty successful and popular in the office. However, it started with users typing in a record key on an HTML form, which they had to look up first, to generate the report. I tried to make this more user-friendly by calling the pdf-gen script and passing the key to it, without the user having to know the key.

That's when I ran into performance troubles...

Server Environment: Windows 2000 Server, Apache 2, Zend WinEnabler with PHP 5

Originally I was getting the user-entered key using $_POST['keyval'] when the user submitted the form. When I tried using http://www.someurl.com/pdf-gen.php?keyval=xxx, and getting the keyval using $_GET['keyval'], the script consistently took about 3 times longer to execute.

For the POST method, I used a single script with the following:

Code: Select all

if (!isset($_POST['submit'])) {
// display HTML form
}
else {
$keyval = $_POST['keyval'];
// generate PDF report
}
For the GET method, I generated a link as mentioned above, and the following:

Code: Select all

if (!isset($_GET['keyval'])) {
// display user notice
}
else {
$keyval = $_GET['keyval'];
// generate PDF report
}
Now, this is a somewhat complex report, using several SQL calls to pull data into string and array variables which are used in script execution, then generating the PDF document and returning it to the browser. No PDF files are created on the server; the generated PDF is streamed directly to the browser. A typical report (from 1-4 pages) takes 10-12 seconds to generate using the POST method. The same report, with the same keyval, using exactly the same code to generate the PDF, essentially differing only by using GET, takes about 30-35 seconds to generate! The results are consistent, and have been roughly timed using a wristwatch and a dozen tests of each method.

It seems GET is the culprit here, as all other elements are as equal as possible. I have tried using PATH_INFO but could not get it to work in this environment; perhaps it is Windows, perhaps using WinEnabler, or perhaps I just couldn't get it configured. GET was the only method I could (so far) successfully pass a value to my script.

The desired functionality (which we do have with GET) is to have the user click a link on a page that "opens" the PDF report -- but with better performance! Can anyone offer an explanation, or suggestions for improving performance?

Thanks for reading my first post!

Daniel
Last edited by CorpDirect on Mon Nov 14, 2005 5:10 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

1st Welcome to DevNet
2nd How many variables are you passing in your query string (Get & Post)?
Are any of them long text strings?
CorpDirect
Forum Newbie
Posts: 6
Joined: Mon Nov 14, 2005 4:17 pm

Post by CorpDirect »

Just the one 'keyval' variable, and it's typically under 10 chars.

Edit: the value is numeric, if that makes a difference; on the HTML form (POST method) it's set as a text field.

Thanks,

Daniel
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I don't believe passing via GET would cause this problem as a matter of fact, if I had to guess I would think POST would be slower.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

hawleyjr wrote:I don't believe passing via GET would cause this problem as a matter of fact, if I had to guess I would think POST would be slower.
Both the same actually. They just put the info in different places in the HTTP request, and that has to be parsed whatever.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

onion2k wrote:
hawleyjr wrote:I don't believe passing via GET would cause this problem as a matter of fact, if I had to guess I would think POST would be slower.
Both the same actually. They just put the info in different places in the HTTP request, and that has to be parsed whatever.

I was thinking slower because of the delay with submitting the form.
CorpDirect
Forum Newbie
Posts: 6
Joined: Mon Nov 14, 2005 4:17 pm

Post by CorpDirect »

Perhaps I'm missing something in the first bit of the scripts; after all, I'm pretty new to PHP. Here's the actual code (the variable obviously is 'SubjectID', not 'keyval' as posted earlier, but this is copied straight from the scripts).

GET method:

Code: Select all

<?php
// if form has not yet been submitted
// display input fields
if (!isset($_GET['SubjectID'])) {
?>

<html>
<body>

<p>
There was no record identifier submitted! The operation cannot continue.<br>
</p>

</body>
</html>

<?php
}
// else process form input and return search results
else {
$SubjectID	=	$_GET['SubjectID'];
// code to generate PDF
}
?>
POST method:

Code: Select all

<?php
// if form has not yet been submitted
// display input fields
if (!isset($_POST['submit'])) {
?>

<html>
<body>
<p>
This form accepts a subject ID and generates the subject search report.<br>
</p>

<FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD=POST enctype="multipart/form-data"">

<p>
Subject ID: <INPUT TYPE="text" NAME="SubjectID" SIZE="20"> <input type="submit" name="submit" value="Search"><br></p>

</FORM>
</body>
</html>

<?php
}
// else process form input and return search results
else {
$SubjectID	=	$_POST['SubjectID'];
// code to generate PDF
}
?>
Aside from the line assigning the $SubjectID value, the scripts are absolutely identical after the else {. Any ideas?

Thanks,

Daniel
CorpDirect
Forum Newbie
Posts: 6
Joined: Mon Nov 14, 2005 4:17 pm

Post by CorpDirect »

Also I've tried removing the top bit from the GET-method script, not testing for a value or returning an error, just generating the PDF, and it makes no difference in speed. You see why I think it has something to do with GET.

Daniel
Post Reply