I have used two php functions to find sunrise but they give answers differing by about five minutes. What did I do wrong, please

<!DOCTYPE html>
<html>
<body>

<?php
//Calculate the sunrise time for a point in Alaska
//Latitude: 61.4 North
//Longitude: 165.5 West
//Zenith ~= 90
//offset: +0 GMT

# The UNIX time stamp is the number of seconds from the start of
# 01 January 1970 

$sun_info = date_sun_info(strtotime("2019-10-30"), 61.4, -165.5 );
foreach ($sun_info as $key => $val) {
    echo "$key: " . date("H:i:s", $val) . "\n";
}

echo("<br>Sunrise time: ");
echo(date_sunrise(strtotime("2019-10-30"),SUNFUNCS_RET_STRING, 61.4,-165.5, 90, 0));

# This is 4 to 5 minutes after date_sun_info
?>

</body>

[Mod: fixed your code tags for you: triple backticks around entire blocks]

    date_sun_info uses the zenith angle configured in php.ini, while date_sunrise allows you to provide it. You've given 90 as the zenith angle to date_sunrise, which probably isn't the same one that date_sun_info is using.

    Interestingly, looking at the configuration documentation it says the default is 90.58333 (date_sun_info says 90°35', which is the same thing). But looking at php.ini itself (the distributed development template) it says 90.833333 is the default value. It looks like a '5' has gone astray somewhere.
    I'm still using the default value, and if I provide a zenith angle of 90.833333 to date_sunrise I get it to produce the same results as date_sun_info.

    Ah-ha: PHP Bug #65547 Default value for sunrise/sunset zenith still wrong

    [All of this business about "zenith angles" is of course due to the fact that the sun isn't a single point source of light, meaning "sunrise" happens before the measured position of the sun is above the horizon even before taking atmospheric refraction into account.]

    Write a Reply...