Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date_sunrise and date_sun_info giving different results

I have a webcam website and I wanted to display the sunrise time for the actual day. So I used the date_sunrise function in PHP for this purpose. In addition to the coordinates, it takes the suns zenith value as input.

I learned that the correct zenith for sunrise is 90.8333. 90 would be the theoretic angle to the center of the sun (i.e. at the horizon). To account for the diameter of the sun and refraction, 0.8333 is added (16 arcminutes + 34 arcminutes divided by 60).

But I noticed that this input gave different sunrise times that other sites. The most reliable source must be the Astronomical Applications Department of the U.S. Naval Observatory. See their online calculator and read the description of their method. It's stated that they also use a Zenith value of 90.8333 for the purpose of calculating sunrise.

Then I discovered that the php function date_sun_info, which is an array containing various data, gave the correct sunrise time (corresponding to the results from AAD).

To achieve the same sunrise time from the date_sunrise function, I have to enter a zenith value around 90.5.

Why doesn't date_sunrise with zenith=90.8333 give the same result as date_sun_info?

like image 688
euphoria Avatar asked Mar 11 '23 04:03

euphoria


1 Answers

According to http://php.net/manual/en/function.date-sunrise.php the default Zenith parameter is taken from a configuration file (See ini_get())

The .ini in question is the php.ini from your PHP install. It has the following lines (they are commented out here, but are used as default unless overwritten in the .ini file).

; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333

Therefore if you navigate to your php.ini file and remove the semi colon, you can overwrite the default sunrise/set zenith values to whatever you wish. In your case, '90.8333'.

In regards to the difference, 'sun_info' takes the arguements of time, longitude and latitude coordinates. So this could have a more accurate database somewhere rather than using the default value set in the config.

References:

  • http://php.net/manual/en/function.date-sun-info.php
  • http://php.net/manual/en/function.date-sunrise.php
  • http://php.net/manual/en/function.ini-get.php
  • http://php.net/manual/en/datetime.configuration.php
like image 88
Dan_ Avatar answered Mar 23 '23 06:03

Dan_