1

I have a page that I am currently writing that is hosted on a singleboard computer. The current webpage that I am coding is used to setup the timezone and current time settings of the board. It features jquery items, javascript functions, a form with 3 submit buttons, php scripts, and a few linux command line exec calls being run, to change the timezone of the board from the commandline. I am also doing more than a handful of string comparisons when determining what the default dropdown item selection should be.

The issue I am having is very repeatable. If I submit the time zone, then change the time, set the time zone again, change the time again, and maybe repeat this one more time, the page doesn't completely load. Upon viewing the source, it is clear that the entire page is not being loaded completely. Usually it ends of failing somewhere within the dropdown selection creation.

For example, this is at the very bottom of the loaded source code file when it fails:

<input class="button" type="submit" name="getLocalTime" value="Copy Local Time"><br><br><br><table><tr><td colspan="2"><tr><td>

<select name="DropDownTimezone" id="DropDownTimezone">
<option  value="Etc/GMT+12">(GMT -12:00) Eniwetok, Kwajalein</option>
<option  value="Etc/GMT+11">(GMT -11:00) Midway Island, Samoa</option>
<option  value="Etc/GMT+10">(GMT -10:00) Hawaii</option>
<option  value="Etc/GMT+9">(GMT -9:00) Alaska</option>
<option  value="Etc/GMT+8">(GMT -8:00) Pacific Time (US &amp; Canada)</option>
<option  value="Etc/GMT+7">(GMT -7:00)

That section is coded like this:

<select name="DropDownTimezone" id="DropDownTimezone">
<option <?php if ($hwOffset == "-12") echo 'selected'; ?> value="Etc/GMT+12">(GMT -12:00) Eniwetok, Kwajalein</option>
<option <?php if ($hwOffset == "-11") echo 'selected'; ?> value="Etc/GMT+11">(GMT -11:00) Midway Island, Samoa</option>
<option <?php if ($hwOffset == "-10") echo 'selected'; ?> value="Etc/GMT+10">(GMT -10:00) Hawaii</option>
<option <?php if ($hwOffset == "-9") echo 'selected'; ?> value="Etc/GMT+9">(GMT -9:00) Alaska</option>
<option <?php if ($hwOffset == "-8") echo 'selected'; ?> value="Etc/GMT+8">(GMT -8:00) Pacific Time (US &amp; Canada)</option>
<option <?php if ($hwOffset == "-7") echo 'selected'; ?> value="Etc/GMT+7">(GMT -7:00) Mountain Time (US &amp; Canada)</option>
<option <?php if ($hwOffset == "-6") echo 'selected'; ?> value="Etc/GMT+6">(GMT -6:00) Central Time (US &amp; Canada), Mexico City</option>
<option <?php if ($hwOffset == "-5") echo 'selected'; ?> value="Etc/GMT+5">(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
<option <?php if ($hwOffset == "-4") echo 'selected'; ?> value="Etc/GMT+4">(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
<option <?php if ($hwOffset == "-3") echo 'selected'; ?> value="Etc/GMT+3">(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
<option <?php if ($hwOffset == "-2") echo 'selected'; ?> value="Etc/GMT+2">(GMT -2:00) Mid-Atlantic</option>
<option <?php if ($hwOffset == "-1") echo 'selected'; ?> value="Etc/GMT+1">(GMT -1:00) Azores, Cape Verde Islands</option>
<option <?php if ($hwOffset == "+0") echo 'selected'; ?> value="Etc/GMT+0">(GMT) Western Europe Time, London, Lisbon, Casablanca</option>
<option <?php if ($hwOffset == "+1") echo 'selected'; ?> value="Etc/GMT-1">(GMT +1:00) Brussels, Copenhagen, Madrid, Paris</option>
<option <?php if ($hwOffset == "+2") echo 'selected'; ?> value="Etc/GMT-2">(GMT +2:00) Kaliningrad, South Africa</option>
<option <?php if ($hwOffset == "+3") echo 'selected'; ?> value="Etc/GMT-3">(GMT +3:00) Baghdad, Riyadh, Moscow, St Petersburg</option>
<option <?php if ($hwOffset == "+4") echo 'selected'; ?> value="Etc/GMT-4">(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
<option <?php if ($hwOffset == "+5") echo 'selected'; ?> value="Etc/GMT-5">(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
<option <?php if ($hwOffset == "+6") echo 'selected'; ?> value="Etc/GMT-6">(GMT +6:00) Almaty, Dhaka, Colombo</option>
<option <?php if ($hwOffset == "+7") echo 'selected'; ?> value="Etc/GMT-7">(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
<option <?php if ($hwOffset == "+8") echo 'selected'; ?> value="Etc/GMT-8">(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
<option <?php if ($hwOffset == "+9") echo 'selected'; ?> value="Etc/GMT-9">(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
<option <?php if ($hwOffset == "+10") echo 'selected'; ?> value="Etc/GMT-10">(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
<option <?php if ($hwOffset == "+11") echo 'selected'; ?> value="Etc/GMT-11">(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
<option <?php if ($hwOffset == "+12") echo 'selected'; ?> value="Etc/GMT-12">(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
</select>

I am thinking that this has something to do with memory running out or a buffer filling up, since it does not fail every time, but will fail after roughly the same number of repeated steps. Are there any useful commands in PHP or methods to avoid having this issue? Or are there any other possible root causes for problems like this? Thanks in advance.

4

2 に答える 2

2

This is not an answer to as of why this happens (as your code looks fine, although ugly, and as others have mentioned, try with error_reporting(E_ALL)). Is this what you receive with jQuery, or is this the HTML output when you load the site?

As an add-on, here's an array version of your code where you should be able to easily incorporate your translations.

<?php
    $timezones = array(
        'Eniwetok, Kwajalein',
        'Midway Island, Samoa',
        'Hawaii',
        'Alaska',
        'Pacific Time (US &amp; Canada)',
        'Mountain Time (US &amp; Canada)',
        'Central Time (US &amp; Canada), Mexico City',
        'Eastern Time (US &amp; Canada), Bogota, Lima',
        'Atlantic Time (Canada), Caracas, La Paz',
        'Brazil, Buenos Aires, Georgetown',
        'Mid-Atlantic',
        'Azores, Cape Verde Islands',
        'Western Europe Time, London, Lisbon, Casablanca',
        'Brussels, Copenhagen, Madrid, Paris',
        'Kaliningrad, South Africa',
        'Baghdad, Riyadh, Moscow, St Petersburg',
        'Abu Dhabi, Muscat, Baku, Tbilisi',
        'Ekaterinburg, Islamabad, Karachi, Tashkent',
        'Almaty, Dhaka, Colombo',
        'Bangkok, HanoiBeijing, Perth, Singapore, Hong Kong, Jakarta',
        'Beijing, Perth, Singapore, Hong Kong',
        'Tokyo, Seoul, Osaka, Sapporo, Yakutsk',
        'Eastern Australia, Guam, Vladivostok',
        'Magadan, Solomon Islands, New Caledonia',
        'Auckland, Wellington, Fiji, Kamchatka'
    );
    echo '<select name="DropDownTimezone" id="DropDownTimezone">';
    for ($i = 0; $i < sizeof($timezones); $i++) {
        $timezone = ($i - 12);
        $timezoneReverse = ($timezone * -1);
        $timezoneValue = ($timezone >= 0 ? '+' . $timezone : $timezone);
        $timezoneReverseValue = ($timezoneReverse >= 0 ? '+' . $timezoneReverse : $timezoneReverse);
        echo '<option' . ($hwOffset == $timezoneValue ? ' selected' : '') . ' value="Etc/GMT' . $timezoneReverseValue . '">(GMT' . ($timezone != 0 ? ' ' . $timezoneValue . ':00' : '') . ') ' . $timezones[$i] . '</option>';
    }
    echo '</select>';
?>

Please note, that this probably won't actually fix your problem, so please don't accept it as a solution, as it's merely an edit of your HTML, but it was a too big change for me to want to edit your OP

于 2012-06-18T13:44:44.927 に答える
0

Unfortunately, and embarrassingly, this issue was related to my form code and had little to do with the timezone dropdown, it just coincidentally failed around there every time. Thank you all for the input on the issue, since it did indeed point my in the right direction (and made me feel stupid haha). Once I started tracking down possible broken variables, I noticed that my form action= item was pointing to a variable to get the filename. I soon realized that the filename had not been set after monitoring the error log for a little while. Once I cleaned that line up, it seemed to fix my other issues strangely enough.

Before: echo "<form method='POST' action='".$PHP_SELF."' onsubmit='getTime();'>";

After: echo "<form method='POST' action='?page=home' onsubmit='getTime();'>";

And this appears to have fixed it. I'm a bit confused as to why it was still submitting, and why it was failing in the manner that it was, but this line appears to have fixed any partially loaded pages that were occurring.

于 2012-06-18T14:16:24.540 に答える