Why is this script so slow?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Foley

    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>Creati ng Export Files<br><br>Pl ease be
    patient.</center><br><Cen ter>
    <?
    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_nam e, "w+") or die("Couldn't create new
    file");
    echo "<br>contact.ta b ";
    flush();

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

    while ($custnumber = mysql_fetch_arr ay($results)) {

    $results2 = mysql_query("SE LECT * from customer where custid =
    ".$custnumb er["custid"]);
    $customer = mysql_fetch_arr ay($results2);

    fwrite($logfile , $custnumber["customer_numbe r"]."\t".$custo mer["name"]."\t".$custo mer["company"]."\t".$custo mer["address"]."\t".$custo mer["state"]."\t".$custo mer["zip"]."\t".$custo mer["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_nam e, "w+") or die("Couldn't create new
    file");

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

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

    while ($custnumber = mysql_fetch_arr ay($results)) {

    $results2 = mysql_query("SE LECT * from customer where custid =
    ".$custnumb er["custid"]);
    $customer = mysql_fetch_arr ay($results2);

    if ($customer["phone"] != "") {
    fwrite($logfile ,
    $custnumber["customer_numbe r"]."\t".$custo mer["phone"]."\tHOME\n") ;
    }
    if ($customer["fax"] != "") {
    fwrite($logfile ,
    $custnumber["customer_numbe r"]."\t".$custo mer["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_nam e, "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("SE LECT DISTINCT custnumber.ID AS
    customer_number , custnumber.gran dtotal, orders.custid FROM orders,
    custnumber WHERE orders.custid = custnumber.scra tch 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_arr ay($results)) {

    $results2 = mysql_query("SE LECT * from customer where custid =
    ".$custnumb er["custid"]);
    $customer = mysql_fetch_arr ay($results2);

    $results3 = mysql_query("se lect * from orders where custid =
    ".$custnumb er["custid"]);
    $order = mysql_fetch_arr ay($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>C ustomer
    #".$custnumb er["customer_numbe r"]."</b><br><br>".$or der["orderdate"]."<BR><BR>".$cu stomer["name"]."<br>".$custom er["address"]."<br>".$custom er["city"].",
    ".$customer["state"]."<BR>".$custom er["zip"]."<BR><BR>".$cu stomer["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>Pay ment 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>Pay ment Amount:</b></td>\n");
    fwrite($logfile , "<td>$".$custnu mber["grandtotal "]."</td>\n");
    fwrite($logfile , "</tr>\n");

    fwrite($logfile , "<tr>\n");
    fwrite($logfile , "<td><b>Request ed Deadline:</b></td>\n");
    fwrite($logfile , "<td colspan=3>".$or der["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("se lect * from orders where custid =
    ".$custnumb er["custid"]);
    while($orders = mysql_fetch_arr ay($results4)) {

    fwrite($logfile , "<tr>\n");
    fwrite($logfile , "<td><b>".$orde rs["project"]."</b></td>\n");
    fwrite($logfile , "<td>".$ord ers["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>Artwor k ".$orders["os"]."
    ".$orders["software"] . " " . $orders["filename"] . "</td>\n");
    fwrite($logfile , "</tr>\n");
    }
    mysql_query("up date orders set imported = 1 where custid =
    ".$custnumb er["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.t ab">contact.tab </a><br>
    <a target="new" href="phone.tab ">phone.tab </a><br>
    <a target="new" href="orderlist .html">orderlis t.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>
Working...