Why is this script so slow?

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Why is this script so slow?

    This script runs fine, but I'd like to know why it's so slow.. Thanks
    for any help out there on how i can make it faster (it might take up
    to 5 min to write these 3 export files whith 15 records each!!!)

    Dan
    ====================
    <style>
    body, table, tr, td {
    font-family: 'verdana';
    font-size: 12px;
    }
    td.header {
    font-weight: bold;
    background-color: #cccccc;
    }
    </style>
    </head>
    <body>
    <br><br><br><br><center>Creating Export Files<br><br>Please be
    patient.</center><br><Center>
    <?
    flush();
    $db = mysql_connect("localhost", "stickerguy", "PASWORDHERE!");
    mysql_select_db("stickerguy",$db);

    // Create contact.tab which is a tab delimated list of customer
    numbers names, address, email
    // order write old file

    // Open contact.tab
    $file_name = "/home/biz/stickerguy/WWW/stickerguyadmin/contact.tab";
    $logfile = fopen($file_name, "w+") or die("Couldn't create new
    file");
    echo "<br>contact.tab ";
    flush();

    // Get all customer numbers
    $results = mysql_query("SELECT DISTINCT custnumber.ID AS
    customer_number, orders.custid FROM orders, custnumber WHERE
    orders.custid = custnumber.scratch AND imported = 0 AND (STATUS =
    'payment received' OR STATUS = 'paypal billing complete') ORDER BY
    custnumber.ID", $db);

    while ($custnumber = mysql_fetch_array($results)) {

    $results2 = mysql_query("SELECT * from customer where custid =
    ".$custnumber["custid"]);
    $customer = mysql_fetch_array($results2);

    fwrite($logfile, $custnumber["customer_number"]."\t".$customer["name"]."\t".$customer["company"]."\t".$customer["address"]."\t".$customer["state"]."\t".$customer["zip"]."\t".$customer["email"]."\n");

    echo ".";
    flush();

    }
    fclose($logfile);

    // Create phone.tab which is a tab delimated list of customer numbers
    and phone numbers
    // over write old file

    // Open phone.tab
    $file_name = "/home/biz/stickerguy/WWW/stickerguyadmin/phone.tab";
    $logfile = fopen($file_name, "w+") or die("Couldn't create new
    file");

    echo "<br>phone.tab .";
    flush();

    // Get all customer numbers
    $results = mysql_query("SELECT DISTINCT custnumber.ID AS
    customer_number, orders.custid FROM orders, custnumber WHERE
    orders.custid = custnumber.scratch AND imported = 0 AND (STATUS =
    'payment received' OR STATUS = 'paypal billing complete') ORDER BY
    custnumber.ID", $db);

    while ($custnumber = mysql_fetch_array($results)) {

    $results2 = mysql_query("SELECT * from customer where custid =
    ".$custnumber["custid"]);
    $customer = mysql_fetch_array($results2);

    if ($customer["phone"] != "") {
    fwrite($logfile,
    $custnumber["customer_number"]."\t".$customer["phone"]."\tHOME\n");
    }
    if ($customer["fax"] != "") {
    fwrite($logfile,
    $custnumber["customer_number"]."\t".$customer["fax"]."\tFAX\n");
    }

    echo ".";
    flush();

    }
    fclose($logfile);

    // Create order list HTML file

    // Open orderlist.html
    $file_name = "/home/biz/stickerguy/WWW/stickerguyadmin/orderlist.html";
    $logfile = fopen($file_name, "w+") or die("Couldn't create new
    file");

    echo "<br>orderlist.html .";
    flush();

    fwrite($logfile, "<html>\n<head>\n<title>Order List</title>\n");
    fwrite($logfile, "<style>\n");
    fwrite($logfile, "td {font-family: Verdana; font-size: 10px;}\n");
    fwrite($logfile, "td.leftbox { font-family: Verdana; font-size:
    10px; background-color: #E8E8E8; }\n");
    fwrite($logfile, "td.box1 { font-family: Verdana; font-size: 10px;
    background-color: #CCCCCC }\n");
    fwrite($logfile, "td.box2 { font-family: Verdana; font-size: 10px;
    background-color: #EEEEEE; }\n");
    fwrite($logfile, "</style></head><body>\n");

    // Get list of all needed customer numbers for order list
    $results = mysql_query("SELECT DISTINCT custnumber.ID AS
    customer_number, custnumber.grandtotal, orders.custid FROM orders,
    custnumber WHERE orders.custid = custnumber.scratch AND imported = 0
    AND (STATUS = 'payment received' OR STATUS = 'paypal billing
    complete') ORDER BY custnumber.ID", $db);

    // Loop thru customer number building table each time
    while ($custnumber = mysql_fetch_array($results)) {

    $results2 = mysql_query("SELECT * from customer where custid =
    ".$custnumber["custid"]);
    $customer = mysql_fetch_array($results2);

    $results3 = mysql_query("select * from orders where custid =
    ".$custnumber["custid"]);
    $order = mysql_fetch_array($results3);

    fwrite($logfile, "<table cellspacing=2 cellpadding=2 width=750
    height=185 border=0>\n");
    fwrite($logfile, "<tr>");

    fwrite($logfile, "<td rowspan=3 class=leftbox
    valign=top><b>Customer
    #".$custnumber["customer_number"]."</b><br><br>".$order["orderdate"]."<BR><BR>".$customer["name"]."<br>".$customer["address"]."<br>".$customer["city"].",
    ".$customer["state"]."<BR>".$customer["zip"]."<BR><BR>".$customer["email"]."<BR>ph:
    ".$customer["phone"]."<br>fx: ".$customer["fax"]."</td>\n");

    fwrite($logfile, "<td class=box1>\n");

    fwrite($logfile, "<table cellpadding=2 border=0 width=100%>\n");

    fwrite($logfile, "<tr>\n");
    fwrite($logfile, "<td><b>Payment Method:</b></td>\n");
    if ($order["status"] == "paypal billing complete") {
    fwrite($logfile, "<td>Pay Pal</td>\n");
    }
    if ($order["status"] == "payment received") {
    fwrite($logfile, "<td>Check/Mail</td>\n");
    }
    fwrite($logfile, "<td><b>Payment Amount:</b></td>\n");
    fwrite($logfile, "<td>$".$custnumber["grandtotal"]."</td>\n");
    fwrite($logfile, "</tr>\n");

    fwrite($logfile, "<tr>\n");
    fwrite($logfile, "<td><b>Requested Deadline:</b></td>\n");
    fwrite($logfile, "<td colspan=3>".$order["deadline"]."</td>\n");
    fwrite($logfile, "</tr>\n");

    fwrite($logfile, "</table>\n");

    fwrite($logfile, "</td>\n");

    fwrite($logfile, "<tr><td class=box2>\n");

    fwrite($logfile, "<table cellpadding=2 border=0 width=100%>\n");


    $results4 = mysql_query("select * from orders where custid =
    ".$custnumber["custid"]);
    while($orders = mysql_fetch_array($results4)) {

    fwrite($logfile, "<tr>\n");
    fwrite($logfile, "<td><b>".$orders["project"]."</b></td>\n");
    fwrite($logfile, "<td>".$orders["quantity"]."
    ".$orders["ordertype"]." ".$orders["size"]."</td>\n");
    fwrite($logfile, "<td>\n");
    if ($orders["vinyl"] != "") {
    fwrite($logfile, "Vinyl: ".$orders["vinyl"] . " "); }
    if ($orders["color1"] != "") {
    fwrite($logfile, "Color1: ".$orders["color1"] . " "); }
    if ($orders["color2"] != "") {
    fwrite($logfile, "Color2: ".$orders["color2"] . " "); }
    if ($orders["color3"] != "") {
    fwrite($logfile, "Color3: ".$orders["color3"] . " "); }
    if ($orders["color4"] != "") {
    fwrite($logfile, "Color4: ".$orders["color4"] . " "); }
    fwrite($logfile, "</td>\n");
    fwrite($logfile, "<td>Artwork ".$orders["os"]."
    ".$orders["software"] . " " . $orders["filename"] . "</td>\n");
    fwrite($logfile, "</tr>\n");
    }
    mysql_query("update orders set imported = 1 where custid =
    ".$custnumber["custid"]);

    fwrite($logfile, "</table>\n");


    fwrite($logfile, "</td></tr>\n");

    fwrite($logfile, "<Tr><td class=box1>" . $customer["notes"] .
    "</td></tr>\n");
    fwrite($logfile, "</table>\n");

    fwrite($logfile, "<hr color=black width=750>\n");

    echo ".";
    flush();

    }

    fwrite($logfile, "</body></html>");







    // Output links to each of the above 3 files.
    ?>
    </center>
    <Br><br>
    <center>
    <a target="new" href="contact.tab">contact.tab</a><br>
    <a target="new" href="phone.tab">phone.tab</a><br>
    <a target="new" href="orderlist.html">orderlist.html</a><br>
    <Br><br>
    Right click the above links and click "save as" or "save target as" to
    save the files. <Br><Br>
    Orders have been marked as processed.

    </center>
    </body>
    </html>
    Dan Foley Guest

  2. Similar Questions and Discussions

    1. Slow FCS or Script issue?
      I installed FCS personal and a videochat script (avchat) It seems works fine but when in the chat we're more than 2 the video stramings stops and...
    2. SLOW DOWN..Why is my Photoshop CS Super Slow in PANTHER?
      G5 DUAL 2GHZ .. 1 GB RAM .. PHOTOSHOP CS .. PANTHER/JAGUAR ........................................................... I've had my DUAL G5 since...
    3. #24580 [Opn->Bgs]: sometimes script runs slow
      ID: 24580 Updated by: sniper@php.net Reported By: longshot at home dot nl -Status: Open +Status: ...
    4. #24580 [NEW]: sometimes script runs slow
      From: longshot at home dot nl Operating system: win XP PHP version: 4.3.2 PHP Bug Type: Performance problem Bug description:...
    5. why does this comparison script run so slow??
      essentially I am trying to do some counts based on some assumptions in the recordset. So I get the RS back, put the values into a variable, move to...
  3. #2

    Default Re: Why is this script so slow?

    I found the same issue with my website.
    Looks like It is the host which is slow sending the email.
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139