A PHP API to parse weather data and weather history from OpenWeatherMap.org.
Clone or download
cmfcmf Merge pull request #122 from Clpsplug/clpsplug/remove_not_so_forecast…

Removed the 'not-so-forecast' measure
Latest commit 92edee8 May 9, 2018


OpenWeatherMap PHP API

A php API to retrieve and parse global weather data from OpenWeatherMap.org. This library aims to normalise the provided data and remove some inconsistencies. This library is neither maintained by OpenWeatherMap nor their official PHP API.

Build Status license release codecov Scrutinizer Quality Score


This library can be found on Packagist. The recommended way to install and use it is through Composer.

composer require "cmfcmf/openweathermap-php-api"

Example call

use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Exception as OWMException;

// Must point to composer's autoload file.
require 'vendor/autoload.php';

// Language of data (try your own language here!):
$lang = 'de';

// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';

// Create OpenWeatherMap object. 
// Don't use caching (take a look into Examples/Cache.php to see how it works).
$owm = new OpenWeatherMap('YOUR-API-KEY');

try {
    $weather = $owm->getWeather('Berlin', $units, $lang);
} catch(OWMException $e) {
    echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
} catch(\Exception $e) {
    echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';

echo $weather->temperature;

For more example code and instructions on how to use this library, please take a look into the Examples folder. Make sure to get an API Key from http://home.openweathermap.org/ and put it into Examples/ApiKey.ini.

  • CurrentWeather.php Shows how to receive the current weather.
  • WeatherForecast.php Shows how to receive weather forecasts.
  • WeatherHistory.php Shows how to receive weather history.
  • Cache.php Shows how to implement and use a cache.


I'm happy about every pull request or issue you find and open to help make this API more awesome.

You can use Vagrant to kick-start your development. Simply run vagrant up and vagrant ssh to start a PHP VM with all dependencies included.

Support me

If you like my work, I'd really appreciate you buying me a coffee. Your donations help me put more time into Open-Source software development.

Buy Me a Coffee at ko-fi.com


MIT — Please see the LICENSE file distributed with this source code for further information regarding copyright and licensing.

Please check out the following official links to read about the terms, pricing and license of OpenWeatherMap before using the service: