1. Go to this page and download the library: Download pastclimate/pastclimate-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pastclimate / pastclimate-php example snippets
astClimate\Client;
$client = new Client(); // reads PASTCLIMATE_API_KEY
$response = $client->getDaily('gb/london', '2024-01-01', '2024-01-31');
foreach ($response->data as $day) {
echo "{$day->date}: {$day->daily_min_temp} to {$day->daily_max_temp}\n";
}
echo "Used {$response->creditsUsed()} credits, {$response->creditsRemaining()} left\n";
$client = new Client(
apiKey: '...', // default: the PASTCLIMATE_API_KEY environment variable
baseUrl: 'https://api.pastclimate.com', // default: PASTCLIMATE_BASE_URL, then this value
timeout: 30.0, // seconds per attempt
maxRetries: 2, // retries after the first try
maxRetryDelay: 60.0, // longest wait the client will sleep between tries
);
use PastClimate\Place;
// 1. A location id: country code, slash, place slug. A plain string works.
$client->getMonthly('gb/london');
$client->getMonthly(Place::id('gb/london'));
// 2. A latitude and longitude, with the two-letter country they are in.
$client->getMonthly(Place::point(51.5, -0.12, 'gb'));
$response = $client->getMonthly('gb/london');
$response->creditsUsed(); // credits this call used
$response->creditsRemaining(); // credits you can still spend (may be null)
$response->meta->methodology_version;
$limit = $response->rateLimit; // the per-minute request limit
$limit->limit; // requests allowed per minute
$limit->remaining; // requests left in this minute
$limit->reset; // seconds until the oldest request leaves the minute window
use PastClimate\Client;
use PastClimate\Http\Psr18Transport;
$client = new Client(
apiKey: getenv('PASTCLIMATE_API_KEY') ?: null,
transport: new Psr18Transport($psr18Client, $psr17RequestFactory),
);
sh
export PASTCLIMATE_API_KEY=your_key_here
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.