Maximum execution time problem

Discussion in 'PHP' started by promotingspace.net, Sep 29, 2008.

  1. #1
    Hi
    I have a table with 3 fields: id, product_id and subcategort_id
    I have repeated data in that table. I wrote the code below to delete the repeated data
    but I got this error:

    Fatal error: Maximum execution time of 60 seconds exceeded in G:\programs\xamp\xampp\htdocs\carat\test.php on line 9
    could you please have a look at the code and suggest how I can avoid this error and do what I need?
    this is the code:

    
    <?php
    include 'connect.php';
    
    $wasbefore=mysql_query("SELECT * FROM prod_subcat ")or die(mysql_error());
    $wasbeforenum=mysql_num_rows($wasbefore);
    echo $wasbeforenum;
    $id=0;
    while($wasbeforenum-$id){
    $wasbefore=mysql_query("SELECT * FROM prod_subcat WHERE id='$id' ")or die(mysql_error());
    $row=mysql_fetch_array($wasbefore);
    $prod=$row['productID'];
    $sub=$row['subcategoryID'];
    $wasbefore=mysql_query("SELECT * FROM prod_subcat WHERE subcategoryID='$sub' AND productID='$prod' ")or die(mysql_error());
    $wasbeforenum=mysql_num_rows($wasbefore);
    if($wasbeforenum>1){
    mysql_query("DELETE FROM `prod_subcat` WHERE `id`='$id' ") or die(mysql_error());
    }
    $id++;
    }
    
    ?>
    
    PHP:

     
    promotingspace.net, Sep 29, 2008 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    put this at the beginning of your code
    @set_time_limit(0);
     
    javaongsan, Sep 29, 2008 IP
  3. spc

    spc Well-Known Member

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    125
    #3
    That may not work, if the server does not allow this onscript modification.

    You can edit the active php.ini (for xampp it is located in xampp/apache/bin directory)
    On the line below
    max_execution_time = 60     ; Maximum execution time of each script, in seconds
    Code (markup):
    change the value of 60 to 120 or whatever you need.

    Then restart the apache server and try.
     
    spc, Sep 30, 2008 IP
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Hi, edit your while loop and make sure its correct. Your while loop is incorrect and it cause an infinite execution time.
     
    php-lover, Sep 30, 2008 IP
  5. imchandan

    imchandan Guest

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    after your first include, put this
    ini_set('max_execution_time','');

    ....
    and when before ?> put, ini_restore('max_execution_time');
     
    imchandan, Sep 30, 2008 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    Change:

    
    while($wasbeforenum-$id){
    
    PHP:
    To:

    
    while($wasbeforenum > $id){
    
    PHP:
    Peace,
     
    Barti1987, Sep 30, 2008 IP
  7. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    solved!
    i used the same variable in while loop and while statement.
     
    promotingspace.net, Sep 30, 2008 IP