problem with popups...

Discussion in 'PHP' started by adolix, Dec 22, 2006.

  1. #1
    Ok, I do very well in PHP, I like it a lot, but this time I have a problem that I can't understand...

    So, here's what is happening: I am working at a site, which will offer some SEO sevices. One of the features is analyzing some pages... this takes much time, so I thought to display a popup, in which to display "Analizing page: XXXX", then reload it after 2 seconds, and display which page is being analized in that moment, and so on....

    The communication of the 2 windows (main and popup) is done using a table, in which the current analyzed link is written...

    So, the main part would be:

    $sql = "SELECT * FROM lg_links WHERE [SPECIFIC CONDITIONS]";
    $result = mysql_query($sql);
    
    while ($row = mysql_fetch_array($result))
       {
       $sid = session_id();
       $sql1 = "UPDATE `lg_status` SET `url`='$row[purl]' WHERE `session`='$sid'";
       $result1 = mysql_query($sql1);
    
       ............. THEN DO THE URL ANALIZING PART..................
       }
    
    PHP:
    The code coresponding to the popup would be:
    
    $sid = session_id();
    $sql = "SELECT * FROM lg_status WHERE session='$sid'";
    $result = mysql_query($sql);
    while ($row = mysql_fetch_array($result))
       {
       $url = $row[url];
       }
    echo "Analyzing $url ...";
    ?><meta http-equiv="Refresh" content="2; URL=/index.php?p=showstatus" /><?php
    
    PHP:
    there are 10 URLs that need to be analyzed (URL1, URL2...... URL10)

    and here is my problem: when the popup is shown, it should say "Analyzing URL1", then later "Analyzing URL2" and so on..... but it says "Analyzing URL10" from the very beginning :eek: although the main page takes about 20-30 seconds to run all the script.... so it's absurd if the popup says the script is at the last URL after 0 seconds :eek:

    pleeeeeeeeeease help me:( I am willing to offer life-time membership to this service I'm working on (which will not be free) to the one that helps me solve this....

    looking forward to your replies... thanks.
     
    adolix, Dec 22, 2006 IP
  2. adolix

    adolix Peon

    Messages:
    787
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #2
    somebody ?
     
    adolix, Dec 26, 2006 IP
  3. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You could use a column where you store the information which site is being analysed right now. You probably have something like where you store one site per row, then you add a column this_site_is_being_analysed_right_now (maybe a bit shorter ;) ) with ENUM values 1 and 0. In the popup you just look for which row has that flag set to 1 for a specific user.
    Or you do it a bit differently and use a column is_analysed. Then you look for rows where that flag is 0.
     
    Icheb, Dec 26, 2006 IP
  4. Evoleto

    Evoleto Well-Known Member

    Messages:
    253
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Looks like PHP is configured to work with buffered output ( http://www.php.net/manual/en/ref.outcontrol.php ) most common the GZip compression output.

    This means the PHP engine will first wait for the script to write all its output, then will do something with that content (usually compress it for faster delivery and bandwidth saving).

    If my assumption is correct, add the following at the beginning of your PHP script:

    
    ini_set("output_buffering", "Off");
    
    PHP:
    Good luck! ;)
     
    Evoleto, Dec 28, 2006 IP
  5. IntelliGuy

    IntelliGuy Banned

    Messages:
    42
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The result of the last analysis (last url, 10th) is still stored in the lg_status when the analysis script finishes. When you start the script again without clearing the lg_status table and if the popup starts loading before starting the analysis script (the probable case) it will show the last url (10th) as being processed. And then probably it will continue from url1 upto url9 in correct order. Either make sure the popup window does not start loading before the main script starts, or clear the lg_status table after the main script ends (and ofcourse the first time now you run it again). The latter is more suitable so that the popup can be started anytime and should show "Ananylis not started yet..." if the lg_status table is empty or the url fiend is empty.
     
    IntelliGuy, Dec 28, 2006 IP
  6. adolix

    adolix Peon

    Messages:
    787
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thank you guys, I'm just leaving the town, going in a short holiday, and will be back online on Jan 2nd. Then I will look into your suggestions and hopefully have the solution :)

    Have a good new year!
     
    adolix, Dec 28, 2006 IP
  7. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #7
    Your update query is somewhat weird ..

    $sql1 = "UPDATE `lg_status` SET `url`='$row[purl]' WHERE `session`='$sid'";

    What's $row[purl] ? Shouldn't it be $row["purl"] (if in fact purl is the name of yur column) ?
     
    kajakske, Dec 28, 2006 IP
  8. Zulu

    Zulu Guest

    Messages:
    83
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    IntelliGuy's analysis seems the most reasonable to me, i will suggest the same.

    No, mate. There is a slight difference between indexing array elements inside and outside a string. Outsite a string, you need to quote the array string keys otherwise php interpreter will try to find a Constant defined with that name and probably print out a warning if it could not find one. Inside a string, you dont need to quote them. If you do quote array string keys inside a string, you will need to enclose the expression in curly braces {$arr['key']} otherwise you will get a parse error. If you do not quote the string keys and use curly braces too {$arr{key]}, now it key will be interpreted as a Constant and not a string key (as you understood without curlies). In short, indexing array elements outside a string and indexing array elements inside a string enclosed by curly braces have the same behaviour. But, without curly braced inside a string, they behave differently. Sorry, if couldnt explain it better. Consult the php documentation page for Strings for more details.

    - Zulu
     
    Zulu, Dec 28, 2006 IP
  9. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The page gets refreshed and the website currently being analyzed is being shown. Output buffering is irrelevant in that case since the last site hasn't been analyzed yet.

    It should actually be $row['purl'] if you want to be specific, so the line should look like this:

    $sql1 = 'UPDATE `lg_status` SET `url`="'. $row['purl'] .'" WHERE `session`="'. $sid. '"';
    PHP:
    But who's counting.
     
    Icheb, Dec 28, 2006 IP
  10. IntelliGuy

    IntelliGuy Banned

    Messages:
    42
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hey dude, read Zulu's post about this. $row[purl] is right syntax when used inside a string without enclosing in curly braces. Though the new code you posted is also perfectly valid.
     
    IntelliGuy, Dec 28, 2006 IP
  11. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hey "dude", I usually don't bother reading posts from guys who don't seem to understand that using the enter key every once in a while actually improves readability.
     
    Icheb, Dec 28, 2006 IP
  12. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #12
    Hey,

    Another possibility ...

    I don't see an order in which you fetch the URLs ... Are you sure it fetches them in the right order and doesn't just start with the last one?

    I'm just guessing here, I have no idea unfortunatly :-(
     
    kajakske, Dec 29, 2006 IP
  13. adolix

    adolix Peon

    Messages:
    787
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #13
    i just put: ini_set("output_buffering", "Off");

    but no effect :(
     
    adolix, Jan 2, 2007 IP
  14. adolix

    adolix Peon

    Messages:
    787
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #14
    adolix, Jan 3, 2007 IP