No announcement yet.

Script Execution Time Question

  • Filter
  • Time
  • Show
Clear All
new posts

  • Script Execution Time Question

    About a year and a half ago I whipped up a simple comments script for my website, Imladris, using php and mysql . Since then it's grown in features and complexity. However, the execution time for the script to run is, on average around four seconds, but sometimes up to 8 or 10. Does this sound like an extreme amount of time for a script to execute? Could it be because some of my mysql calls aren't optimized? Anyway, you can take a look at the script right here

  • #2
    Yes it could very well be your mysql queries causing the slow response times.

    What you can do is take your queries one by one and type them into MySQL (or phpMyAdmin) but append EXPLAIN to the beginning of them. This will spit out how many rows had to be scanned and what indexes are being used. You can attach &explain=1 to the end of any url of a vbulletin forum to get a view of what the output looks like.

    If your script is using the same database as your vB forums are then you can put an include('./global.php'); at the top of your script and then attach the &explain=1 to your script url to have vB do the explaining for you.


    • #3
      Thanks for the advice! Looks like the culprit is one of my queries - select * from comments where parentid = '$parentid'. It's having to search through all 30,000 records. I made parentid an index (along with a couple of others that are already set), but after doing so the execution time to up to 50 seconds. Any suggestions - besides brushing up on mysql which I definitely plan to do .


      • #4
        I can't really help any more without seeing your script and your database layout.


        • #5
          Ok not sure if this will help or not, but below is a dump of my comments table's structure. The field "parentid" is causing the problem in my "select" queries. When doing an explain it shows that mysql must search through all 30,000 rows of data to find the results. I thought that making "parentid" an index would take care of the problem, but instead my scripts took even longer to execute.

          CREATE TABLE allcomments (
             name tinytext NOT NULL,
             parentid int(4) DEFAULT '0' NOT NULL,
             email tinytext NOT NULL,
             title tinytext NOT NULL,
             comment blob NOT NULL,
             date tinytext NOT NULL,
             id int(4) NOT NULL auto_increment,
             registered tinytext NOT NULL,
             pw tinytext NOT NULL,
             ip tinytext NOT NULL,
             ontopic tinytext NOT NULL,
             sig text NOT NULL,
             parentcom int(11) DEFAULT '0' NOT NULL,
             comgroup text NOT NULL,
             PRIMARY KEY (id),
             UNIQUE id (id),
             KEY parentcom (parentcom)


          • #6

            Ah, nevermind, think I've fixed it. Thanks for the explain query bit - helped a ton


            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.