PHPackages                             akhela/website-carbon-calculator - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. akhela/website-carbon-calculator

Abandoned → [sustainableWeb/website-carbon-calculator](/?search=sustainableWeb%2Fwebsite-carbon-calculator)Library[Utility &amp; Helpers](/categories/utility)

akhela/website-carbon-calculator
================================

Lightweight and framework-agnostic PHP library to calculate web page carbon emissions based on real-time parameters. No external API required — ideal for custom integrations, CLI tools, or backend automation.

2.0.1(4mo ago)9302[2 PRs](https://github.com/sustainablewebdev/website-carbon-calculator/pulls)1MITPHP

Since Apr 1Pushed 4mo agoCompare

[ Source](https://github.com/sustainablewebdev/website-carbon-calculator)[ Packagist](https://packagist.org/packages/akhela/website-carbon-calculator)[ RSS](/packages/akhela-website-carbon-calculator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (1)

Website Carbon Calculator
-------------------------

[](#website-carbon-calculator)

The internet consumes a lot of electricity. 1021 TWh per year to be precise. To give you some perspective, that’s more than the entire United Kingdom.

From data centers to transmission networks to the billions of connected devices that we hold in our hands, it is all consuming electricity, and in turn producing carbon emissions equal to or greater than the global aviation industry. Yikes!

The Website Carbon Calculator empowers website owners to assess and minimize their carbon footprint. Drawing inspiration from the acclaimed Website Carbon Calculator algorithm 2.0 and leveraging The Green Web Foundation's co2.js, it allows you to calculate the CO₂ impact and performance of any url.

### Installation

[](#installation)

```
$ composer require sustainableweb/website-carbon-calculator
```

### API

[](#api)

#### Estimate web page carbon footprint and performance

[](#estimate-web-page-carbon-footprint-and-performance)

View the [Google documentation](https://developers.google.com/speed/docs/insights/v5/get-started#APIKey) to generate a Google Pagespeed Api Key

```
use SustainableWeb\WebsiteCarbonCalculator\WebsiteCarbonCalculator;

$websiteCarbonCalculator = new WebsiteCarbonCalculator('GooglePagespeedApiKey');
$websiteCarbonCalculator->calculateByURL('https://www.websitecarbon.com/how-does-it-work/', ['strategy'=>'desktop'])
```

Output

```
{
  "url": "https://www.websitecarbon.com",
  "isGreenHost": true,
  "bytesTransferred": 135289,
  "networkRequests": 16,
  "performanceScore": 0.94,
  "loadingExperience": "FAST",
  "domSize": 308,
  "speedIndex": 934,
  "firstMeaningfulPaint": 491,
  "interactive": 692,
  "bootupTime": 94,
  "serverResponseTime": 150,
  "mainthreadWork": 762,
  "energy": 0.000171,
  "co2PerPageview": 0.0739
}
```

For better performance, detect hosting energy type and store it in a database to avoid repetitive call to The Green Web Foundation API.

#### Detect hosting energy type

[](#detect-hosting-energy-type)

```
use SustainableWeb\WebsiteCarbonCalculator\WebsiteCarbonCalculator;

$isGreenHost = WebsiteCarbonCalculator::isGreenHost('https://www.websitecarbon.com')
$websiteCarbonCalculator->calculateByURL('https://www.websitecarbon.com/how-does-it-work/', ['isGreenHost'=>$isGreenHost, 'strategy'=>'desktop'])
```

### How does it work

[](#how-does-it-work)

Calculating the carbon emissions of website is somewhat of a challenge, but using five key pieces of data we can make a pretty good estimate:

- Data transfer over the wire
- Energy intensity of web data
- Energy source used by the data center
- Carbon intensity of electricity
- Website traffic

Under the hood, it uses [Google pagespeed api](https://developers.google.com/speed/docs/insights/v5/get-started) and [The green web foundation api](https://www.thegreenwebfoundation.org/green-web-check/)

### Website Carbon Calculator

[](#website-carbon-calculator-1)

This project is widely inspired by the [Website Carbon Calculator algorithm 2.0](https://gitlab.com/wholegrain/carbon-api-2-0) and [The Green Web Foundation co2.js](https://github.com/thegreenwebfoundation/co2.js)

### Glossary

[](#glossary)

- strategy : mobile/desktop
- isGreenHost : server uses sustainable energy
- networkRequests :
- performanceScore :
- domSize :
- speedIndex :
- firstContentfulPaint :
- largestContentfulPaint :
- interactive :
- bootupTime :
- serverResponseTime :
- mainthreadWork :
- co2PerPageview : estimated grams of CO2 produced every time someone visits the web page

### Tests

[](#tests)

Run tests

```
$ pagespeedApiKey=xxxxxx php vendor/bin/phpunit
```

### Changelog

[](#changelog)

2.0.1
=====

[](#201)

- remove warnings thrown when Google API response is not complete

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance74

Regular maintenance activity

Popularity15

Limited adoption so far

Community10

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

Every ~271 days

Recently: every ~317 days

Total

6

Last Release

147d ago

Major Versions

1.1.1 → 2.0.02025-05-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/81323b7397ffbf98d565129cd7331941cf2d81e30a2bea4fab3f1b43e59375ff?d=identicon)[sustainablewebdev](/maintainers/sustainablewebdev)

---

Top Contributors

[![jerome-barbato](https://avatars.githubusercontent.com/u/4919596?v=4)](https://github.com/jerome-barbato "jerome-barbato (15 commits)")

---

Tags

backendcarbon-emissionscarbon-footprintco2co2-calculatoreco-designgreen-websustainabilityweb-performance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/akhela-website-carbon-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/akhela-website-carbon-calculator/health.svg)](https://phpackages.com/packages/akhela-website-carbon-calculator)
```

###  Alternatives

[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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