PHPackages                             monkeyphp/open-weather-map - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. monkeyphp/open-weather-map

ActiveLibrary[API Development](/categories/api)

monkeyphp/open-weather-map
==========================

Client library for accessing the OpenWeatherMap API

0.1(12y ago)02.0kGPLPHP

Since Feb 11Pushed 12y ago2 watchersCompare

[ Source](https://github.com/monkeyphp/open-weather-map)[ Packagist](https://packagist.org/packages/monkeyphp/open-weather-map)[ Docs](http://github.com/monkeyphp/open-weather-map)[ RSS](/packages/monkeyphp-open-weather-map/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (14)Versions (2)Used By (0)

OpenWeatherMap
==============

[](#openweathermap)

A PHP client library for accessing the [OpenWeatherMap](http://openweathermap.org) Api.

[![Build Status](https://camo.githubusercontent.com/30bf7a7be859d1e915f4892cd9b72e0602b3bf55ada3a2f674e3e2fe6050787d/68747470733a2f2f7472617669732d63692e6f72672f6d6f6e6b65797068702f6f70656e2d776561746865722d6d61702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/monkeyphp/open-weather-map)[![Latest Stable Version](https://camo.githubusercontent.com/2c66b2b0980befc707dfe83c764defabb4b3988bf3e8812e8463f72558807913/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e6b65797068702f6f70656e2d776561746865722d6d61702f762f737461626c652e706e67)](https://packagist.org/packages/monkeyphp/open-weather-map)[![Total Downloads](https://camo.githubusercontent.com/e0dbfb8323cb19ea91f74e8e1b14751d4e5e40a2abf8ba111ea34cb67a2df06a/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e6b65797068702f6f70656e2d776561746865722d6d61702f646f776e6c6f6164732e706e67)](https://packagist.org/packages/monkeyphp/open-weather-map)[![Latest Unstable Version](https://camo.githubusercontent.com/305fe8fafa728f220975d201700b6591126fc14d0157829ee34ff88e62a26bed/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e6b65797068702f6f70656e2d776561746865722d6d61702f762f756e737461626c652e706e67)](https://packagist.org/packages/monkeyphp/open-weather-map)[![License](https://camo.githubusercontent.com/e6d4119026301b6526691f78d291d56ad91016c6912ca3bc8303610c6ceee004/68747470733a2f2f706f7365722e707567782e6f72672f6d6f6e6b65797068702f6f70656e2d776561746865722d6d61702f6c6963656e73652e706e67)](https://packagist.org/packages/monkeyphp/open-weather-map)

The OpenWeatherMap library is a client library for accessing weather data from the free [OpenWeatherMap](http://openweathermap.org/) Api.

You can read more about OpenWeatherMap [here](http://openweathermap.org/).

The library is built on top of a number of [Zend Framework 2](http://framework.zend.com/manual/2.2/en/index.html) components.

Links
-----

[](#links)

-
-

Get the OpenWeatherMap library
------------------------------

[](#get-the-openweathermap-library)

The easiest way to get the library is to use [Composer](https://getcomposer.org/)and [Packagist](http://packagist.org/).

If you do not already have Composer in your application, you can install it as follows.

```
$ curl -sS https://getcomposer.org/installer | php

```

Create the `composer.json` file.

```
$ touch composer.json

```

Add the following to the `composer.json` file

```
{
    "require": {
        "monkeyphp/open-weather-map" "*"
    }
}

```

Finally run Composer install

```
$ php composer.phar install

```

You should now have the library installed into your `vendors` directory.

### Autoloading the OpenWeatherMap library

[](#autoloading-the-openweathermap-library)

The easiest way to start using OpenWeatherMap is to use the Composer autoloader.

Include the Composer autoloader into your script

```
require_once "vendor/autoload.php";

```

Create an instance of OpenWeatherMap
------------------------------------

[](#create-an-instance-of-openweathermap)

The OpenWeatherMap library provides a top level class `OpenWeatherMap` that all available functionality can be accessed through.

A default instance (without any parameters) can be constructed as follows:

```
$openWeatherMap = new OpenWeatherMap\OpenWeatherMap();

```

You can alos construct an instance of `OpenWeatherMap` you can also supply a set of constructor options.

The accepted keys to the constructor are:

 defaults Supply an array of query values that will be used as parameters in subsequent queries connectorFactory For example, we can create an instance of `OpenWeatherMap` as follows

```
$options = array (
    'defaults' => array (
        'apikey' => _YOURAPIKEY_,
        'mode'   => 'xml',
        'query'  => 'London,UK'
    )
);
$openWeatherMap = new OpenWeatherMap\OpenWeatherMap($options);

```

Now all subsequent queries will automatically include the supplied **apiKey**, **mode** and **query** value.

```
$current = $openWeatherMap->weather();

```

ConnectorFactory and Connectors
-------------------------------

[](#connectorfactory-and-connectors)

Internally, the OpenWeatherMap library uses a factory class to manage the plumbing for connecting to the OpenWeatherMap Api.

The primary role of the ConnectorFactory is to create Connector classes that are then used to query each of the endpoints that the OpenWeatherMap Api exposes.

Each of the Connector classes requires a Lock classes that manages throttling calls to the api.

Locking
-------

[](#locking)

The OpenWeatherMap utilises a simple locking mechanism to throttle requests to the  api.

To quote the openweathermap.org docs

> Do not send requests more then 1 time per 10 minutes from one device. The weather is changing not so frequently as usual.

The locking mechanism is enabled by default to work in accordance with the above recommendation from openweathermap.org and should work out of the box.

What this means is that requests to the openweathermap.org api are throttled to one request every 10 minutes (or 600 seconds).

It is possible to override the default implementation by constructing the OpenWeatherMap instance with the following parameters, setting 'minLifetime' to the limit you require.

For example, set this value to 300 to throttle requests to 1 time per 5 minutes.

```
$options = array(
    'connectorFactory' => array(
        'lock' => array(
            'options' => array(
                'minLifetime' => 300
            )
        )
    )
);
$openWeatherMap = new OpenWeatherMap\OpenWeatherMap($options);

```

It is also possible to construct a Lock instance first and pass that to the constructor in the options array.

```
$lock = new OpenWeatherMap\Lock\Lock(array(
    'minLifetime' => 300,
));
$options = array(
    'connectorFactory' => array(
        'lock' => $lock
    )
);
$openWeatherMap = new OpenWeatherMap\OpenWeatherMap($options);

```

It is also possible to enable locking that allows queries to be made irrespective of throttling.

```
$lock = new OpenWeatherMap\Lock\Lock(array(
    'minLifetime' => null
));

```

The Lock class supports the following options

 file The path of the lock file. maxLifetime The maximum number of seconds before a lock if forceably released. minLifetime The minium number of seconds that a lock lives for.```
$lock = new OpenWeatherMap\Lock\Lock(array(
    'file'        => '/tmp/my.lock',
    'minLifetime' => 100,
    'maxLifetime' => 150
));

```

\##Using the OpenWeatherMap instance

Once you have constructed an `OpenWeatherMap` instance, configured to your needs, you can now start using it to query the api.

There are 3 methods that the `OpenWeatherMap` exposes.

All 3 methods accept an array of values, which may contain the following keys.

 latitude ```
longitude

id

query

apiKey

count

mode

units

language

```

In the array of options, you must provide at least one of the following (in preference order):

1. **query**
2. **latitude** and **longitude**
3. **id**

The above keys are used in part of a preferential order.

For example, supplying both **query** and **id** will result in the **query** value being used to query the OpenWeatherMap Api with as that has a higher preference.

### Get the current weather

[](#get-the-current-weather)

If you supplied a set of default options when you created the OpenWeatherMap, then you can just make the call.

```
$weather = $openWeatherMap->getWeather();

```

If you created a default instance of OpenWeatherMap, then you will need to supply an array of options when you make the call.

Remember that you *must* provide an id, a query or a latitude and longitude value.

```
$options = array(
    'query' => 'London,uk',
    'mode'  => 'xml'
);
$current = $openWeatherMap->getWeather($options);

```

OpenWeatherMap::getWeather() will return an instance of OpenWeatherMap\\Entity\\Current which can then be queried for the details about the current weather.

```
$city        = $current->getCity();
$weather     = $current->getWeather();
$temperature = $current->getTemperature();

echo getValue()}.
The temperature will be between {$temperature->getMin()}
and {$temperature->getMax()} {$temperature->getUnit()}.
EOT;

```

### Get the daily forecast

[](#get-the-daily-forecast)

If you supplied a set of default options when you created the OpenWeatherMap, then you can just make the call.

```
$weatherData = $openWeatherMap->getDaily();

```

If you created a default instance of OpenWeatherMap, then you will need to supply an array of options when you make the call.

Remember that you *must* provide an id, a query or a latitude and longitude value.

```
$options = array(
    'query' => 'London,uk',
    'mode'  => 'xml'
);
$weatherData = $openWeatherMap->getDaily($options);

```

### Get the hourly forecast

[](#get-the-hourly-forecast)

If you supplied a set of default options when you created the OpenWeatherMap, then you can just make the call.

```
$weatherData = $openWeatherMap->getForecast();

```

If you created a default instance of OpenWeatherMap, then you will need to supply an array of options when you make the call.

Remember that you *must* provide an id, a query or a latitude and longitude value.

```
$options = array(
    'query' => 'London,uk',
    'mode'  => 'xml'
);
$weatherData = $openWeatherMap->getForecast($options);

```

Run the PHPUnit tests
---------------------

[](#run-the-phpunit-tests)

The library is tested with [PHPUnit](http://phpunit.de/).

```
$ vendor/bin/phpunit -c tests/phpunit.xml

```

Run the PHP CS tests
--------------------

[](#run-the-php-cs-tests)

The library uses a PSR compatible coding standard.

```
$ vendor/bin/phpcs --standard="PSR2" src/

```

License
-------

[](#license)

Copyright (C) 2014 David White

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see \[\].

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4522d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1448153?v=4)[MonkeyPHP](/maintainers/MonkeyPHP)[@monkeyphp](https://github.com/monkeyphp)

---

Top Contributors

[![monkeyphp](https://avatars.githubusercontent.com/u/1448153?v=4)](https://github.com/monkeyphp "monkeyphp (143 commits)")

---

Tags

apiclientweatheropen weather map

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/monkeyphp-open-weather-map/health.svg)

```
[![Health](https://phpackages.com/badges/monkeyphp-open-weather-map/health.svg)](https://phpackages.com/packages/monkeyphp-open-weather-map)
```

###  Alternatives

[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

46688.8k5](/packages/deepseek-php-deepseek-php-client)[rakibdevs/openweather-laravel-api

Laravel package to connect https://openweathermap.org/ to get customized weather data for any location on the globe immediately

7651.3k](/packages/rakibdevs-openweather-laravel-api)[evandotpro/edp-github

Github API integration module for Zend Framework 2

242.2k](/packages/evandotpro-edp-github)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
