我有一个当前正在编写的页面,该页面托管在单板计算机上。我正在编码的当前网页用于设置板子的时区和当前时间设置。它具有jquery项,javascript函数,带有3个提交按钮的表单,php脚本和一些正在运行的linux命令行exec调用,可从命令行更改开发板的时区。在确定默认下拉菜单项应该是什么时,我还进行了很多字符串比较。
我遇到的问题是非常可重复的。如果我提交时区,然后更改时间,再次设置时区,再次更改时间,也许再重复一次,则页面不会完全加载。查看源代码后,很明显整个页面没有完全加载。通常,它会在下拉选择创建过程中某处失败而结束。
例如,这在失败时位于已加载源代码文件的最底部:
<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 & Canada)</option>
<option value="Etc/GMT+7">(GMT -7:00)
该部分的编码如下:
<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 & Canada)</option>
<option <?php if ($hwOffset == "-7") echo 'selected'; ?> value="Etc/GMT+7">(GMT -7:00) Mountain Time (US & Canada)</option>
<option <?php if ($hwOffset == "-6") echo 'selected'; ?> value="Etc/GMT+6">(GMT -6:00) Central Time (US & Canada), Mexico City</option>
<option <?php if ($hwOffset == "-5") echo 'selected'; ?> value="Etc/GMT+5">(GMT -5:00) Eastern Time (US & 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>
我认为这与内存用完或缓冲区已满有关,因为它不会每次都失败,但是在经过大致相同数量的重复步骤后会失败。 PHP或方法中是否有任何有用的命令可以避免出现此问题?还是有其他可能导致此类问题的根本原因?提前致谢。
最佳答案
这不是为什么发生这种情况的答案(因为您的代码看起来不错,尽管很丑陋,并且正如其他人提到的,请尝试使用error_reporting(E_ALL)
)。这是通过jQuery收到的,还是加载网站时的HTML输出?
作为附加组件,这是代码的数组版本,您应该可以在其中轻松合并翻译。
<?php
$timezones = array(
'Eniwetok, Kwajalein',
'Midway Island, Samoa',
'Hawaii',
'Alaska',
'Pacific Time (US & Canada)',
'Mountain Time (US & Canada)',
'Central Time (US & Canada), Mexico City',
'Eastern Time (US & 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>';
?>
请注意,这实际上可能无法解决您的问题,所以请不要接受它作为解决方案,因为它只是对HTML的编辑,但是对我来说,要编辑您的OP