performance hit using $_GET[]
Posted: Mon Nov 14, 2005 4:57 pm
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:
For the GET method, I generated a link as mentioned above, and the following:
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
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
}Code: Select all
if (!isset($_GET['keyval'])) {
// display user notice
}
else {
$keyval = $_GET['keyval'];
// generate PDF report
}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