Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Something is timing out

Links for php scripts

Moderators: macek, egami, gesf

Something is timing out

Postby mhillman » Sun Jun 30, 2013 6:11 am

I have a problem which is difficult to describe, but I'll give it a go.

1. I have a php page which has nothing but 4 buttons on it which are used to launch various scripts. The button in question is coded as:
Code: Select all
<form action="/import/VerifyDXCC.php" method="POST">
<input type="submit" style="width:150px" value="Validate QSO's" />
</form>


2. VerifyDXCC.php does a MySQL SELECT, and for each record I do an operation that takes 2-5 seconds.

With small amounts of data (say 10-20 records), it all works fine. For large sets (~700) I get no error and no script completion. It just sits there waiting for the page to complete. I can tell that the script is actually completing because all database entries are updated, but after updating all records, which could take 20-30 mins, the script just hangs.

VerifyDXCC.php code below.
Code: Select all
<?php
session_start();
assert(isset($_SESSION['memberNum']), "Session variable memberNum not defined");
include "db.php";
include "set.php";

    global $con;
    $DXCCVerified = 0;
    $DXCCNoMatch  = 0;
    $DXCCNotFound = 0;
    $memberNum    = $_SESSION['memberNum'];
    ob_implicit_flush(true);    // output immediately
    // Select all QSO where DXCC has not been verified
    $result = mysqli_query($con, "SELECT * FROM QSO WHERE memberNum=" . $memberNum . " AND FIND_IN_SET('DXCC_OK',FLAGS)=0") or die('PHP error File: __FILE__ line: __LINE__ function: __FUNCTION __ - Error in query (' . mysqli_errno($con) . ') ' . mysqli_error($con));
    $DXCCRecords = mysqli_num_rows($result);
    echo $DXCCRecords . " DXCC to be checked<br>";
    while ($row = mysqli_fetch_assoc($result))
    // Check the DXCC number from ClubLog
        {
        set_time_limit(30); // refresh page timeout       
        $QSO_Detail = "Call " . $row['CALLSIGN'] . " " . $row['QSO_DATE'] . " " . $row['TIME_OFF'] . " " . $row['BAND'] . " " . $row['MODE']; // QSO detail
        $dxcc       = getDXCCClubLog($row['CALLSIGN'], $row['QSO_DATE']); // get the DXCC from ClubLog
        if ($dxcc == 0) {
            // ClubLog could not determine DXCC
            $DXCCNotFound++;
            echo "Unable to determine DXCC for " . $QSO_Detail . " at clublog.org<br>";
        } else if ($dxcc <> $row['DXCC']) {
            // DXCC do not match 
            $DXCCNoMatch++;
            echo "The DXCC reported by clublog.org (" . $dxcc . ") for " . $QSO_Detail . " differs from that in your log (" . $row['DXCC'] . ")<br>" . "       Visit the ClubLog call tester https://secure.clublog.org/test.php for more detail<br>";
        } else {
            // They are equal - validate DXCC     
            $DXCCVerified++;
            $PrimaryKey = "memberNum=" . $memberNum . " AND STATION_CALLSIGN='" . $row['STATION_CALLSIGN'] . "' AND CALLSIGN='" . $row['CALLSIGN'] . "' AND QSO_DATE='" . $row['QSO_DATE'] . "' AND TIME_OFF='" . $row['TIME_OFF'] . "' AND BAND='" . $row['BAND'] . "'";
            $flags      = new set($row['FLAGS']);
            $flags      = $flags->add('DXCC_OK'); // set the DXCC flag
            $flagst     = $flags->__toString(); // convert to string
            $sql        = "UPDATE QSO SET FLAGS='" . $flagst . "' WHERE " . $PrimaryKey;
            mysqli_query($con, $sql) or die('PHP error File: __FILE__  line: __LINE__ function: __FUNCTION __ - Error in query(' . mysqli_errno($con) . ') ' . mysqli_error($con)); // update the database
            echo "DXCC validated for " . $QSO_Detail . "<br>";
        }
    }
    mysqli_free_result($result);
    echo "Verifying of DXCC complete<br>";
    echo "<table border=1>";
    echo "<tr><td>Records checked</td><td>$DXCCRecords</td></tr>";
    echo "<tr><td>Records verified</td><td>$DXCCVerified</td></tr>";
    echo "<tr><td>DXCC are different</td><td>$DXCCNoMatch</td></tr>";
    echo "<tr><td>DXCC not found</td><td>$DXCCNotFound</td></tr>";
    echo "</table>";
    return;

function getDXCCClubLog($callsign, $dt)
{
    // Convert a Callsign to a DXCC entity
    echo "Checking Clublog for " . $callsign . "<br>";
    $apikey = "10c";
    $calls  = str_replace("/QRP", "", $callsign); // ignore low power
    $date   = explode("-", $dt);
    $url    = "https://secure.clublog.org/test.php?call=" . $calls . "&api=" . $apikey . "&year=" . $date[0] . "&month=" . $date[1] . "&day=" . $date[2];
    $result = file_get_contents($url);
    return (int) $result;
}
?>


I have put a " set_time_limit(30);" at the beginning of processing each record to stop the page timing out, but obviously something else is timing out (with no error message). Any suggestions as to what it could be?
mhillman
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sun Jun 30, 2013 5:59 am

Return to PHP Scripts

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron