Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007
    Posts
    2

    Unanswered: How to solve this timeout problem?

    I developed this script to update the PR value for the urls in my database, and then output the old and new pr browser for comparison. I have more than 1000 urls in the database, however, the script will always stops at around #500 urls.

    Can anybody check the script and give me a solution?

    $prupdate = new pageRank(); //pageRank() is the class for updating pr. $count = 1;
    $total = 0;
    $qry = mysql_query("SELECT id, url, pr FROM sub_dirs WHERE status = 1");
    while($result = mysql_fetch_array($qry))
    {
    $id = $result['id'];
    $url = $result['url'];
    $oldpr = $result['pr'];
    $newpr = $prupdate->printrank($url);
    if(!$newpr) $newpr = 0;
    $pr_diff = $newpr - $oldpr;
    $total = $total + $pr_diff;
    //if update successful, output the new and old pr values.
    if(mysql_query("UPDATE sub_dirs SET pr = ".$newpr." WHERE id = ".$id.""))
    {
    if($count%2 == 0) echo "<tr bgcolor=\"#D7E1FF\">";
    else echo "<tr>";
    echo "<td width=\"50\"><div align=\"center\">" .$count. "</div></td>";
    echo "<td width=\"300\"><a href=\"http://" .$url. "\" target=\"_blank\">" .$url. "</td>";
    echo "<td width=\"100\" class=\"oldpr\"><div align=\"center\">" .$oldpr. "</div></td>";
    echo "<td width=\"100\" class=\"newpr\"><div align=\"center\">" .$newpr. "</div></td>";
    echo "<td width=\"100\" class=\"pr_diff\"><div align=\"center\">" .$pr_diff. "</div></td>";
    echo "</tr>";
    }
    else
    {
    if($count%2 == 0) echo "<tr bgcolor=\"#D7E1FF\">";
    else echo "<tr>";
    echo "<td width=\"50\"><div align=\"center\">" .$count. "</div></td>";
    echo "<td width=\"300\"><a href=\"http://" .$url. "\" target=\"_blank\">" .$url. "</td>";
    echo "<td width=\"300\" colspan=\"3\" class=\"pr_diff\"><div align=\"center\">Errors while updating PR</div></td>";
    echo "</tr>";
    }
    $count++;

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you can adjust the execution time of a script either in the PHP config file php.ini and optionally at runtime within the script itself.
    however your ISP may have set a max execution time in the config file whihc limits howfar you can extend the time limit; see for details

    however if you only have 1000 URL's then Id suspect you have an algolrythm problem,rather than a PHP script problem. IE changing the script execution time isn't going to fix the problem merely the current symptoms of the problem. By that I mean I suspect your method to calculate the pagerank is not especially efficient.

    For what you are trying to do Id expect a different approach
    step one find if there is a record for this URL
    if so increment it
    if not then add a record for this URL..

    for its faults SQL is a very effective tool at data manipulation.. far better than any development language such as PHP or ASP, and better than VB, VC, Java or whatever

    id want to check that I was able to use some indexes on the table

    like all optimising / timing problems it helps if you first of all try to work out where the time is going. IE what section of the code is taking the time.
    some that could be the query, some of that could the the php, some of that could be a network problem.. gettign the data from MySQL to the Web server (ok thats unlikely in the modern era but it may be happening).

    it may be that the class is doing something that is hogging the cpu... I'd suggest that before you redesign the app... get soem metrics on what step is taking what time. The precise values don't matter.. but for example taking a snapshot after each line gives an idea of where the resources are going.

  3. #3
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    You can simply use set_time_limit(0); on the first line of your code and the script will not stop before completing the execution of you query.
    Freelance and Technology Consultant
    -------------------
    Dreams are for ever
    -------------------

Posting Permissions

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