PHPackages                             ankitjain28may/hackerearth-api - 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. ankitjain28may/hackerearth-api

ActiveLibrary[API Development](/categories/api)

ankitjain28may/hackerearth-api
==============================

PHP and Laravel HackerEarth API Wrapper

V0.1(8y ago)8441[2 issues](https://github.com/ankitjain28may/hackerearth-api/issues)[2 PRs](https://github.com/ankitjain28may/hackerearth-api/pulls)MITPHPPHP &gt;=5.6.4

Since Jul 8Pushed 3y ago2 watchersCompare

[ Source](https://github.com/ankitjain28may/hackerearth-api)[ Packagist](https://packagist.org/packages/ankitjain28may/hackerearth-api)[ RSS](/packages/ankitjain28may-hackerearth-api/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

HackerEarth API
===============

[](#hackerearth-api)

[![Latest Stable Version](https://camo.githubusercontent.com/07bdf28bbb4dfcb36d8137f2c1eff037d46d72c33c674917a90d01ca0cec6bce/68747470733a2f2f706f7365722e707567782e6f72672f616e6b69746a61696e32386d61792f6861636b657265617274682d6170692f762f737461626c65)](https://packagist.org/packages/ankitjain28may/hackerearth-api)[![Build Status](https://camo.githubusercontent.com/82e180b341e2fbe94cb83c8bedc07a77f2089e5223199e1477e101603a8eb7ba/68747470733a2f2f7472617669732d63692e6f72672f616e6b69746a61696e32386d61792f6861636b657265617274682d6170692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ankitjain28may/hackerearth-api)[![Coverage Status](https://camo.githubusercontent.com/2b12c3f32338159a397e87a039859c871e07adf7aefe018ed8f443d20ab77f22/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f616e6b69746a61696e32386d61792f6861636b657265617274682d6170692f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ankitjain28may/hackerearth-api?branch=master)[![Packagist](https://camo.githubusercontent.com/3841e91d14d91424b745a9e09ca4a3445532a9cb3ce1d0a47652f0de1d27f7a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e6b69746a61696e32386d61792f6861636b657265617274682d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ankitjain28may/hackerearth-api)

This package is using HackerEarth api to Compile and Run the code.

HackerEarth Code Checker API. Extremely simple REST API. Supports more than a dozen languages. All powered by reliable HackerEarth servers. You can use your own scoring system or build your own online judge.

[![](https://camo.githubusercontent.com/fe57c4c057a2f4deeaef9ea59463ccb88f4fa362499336ac31c5a14bec4681a2/68747470733a2f2f66696c65732e706870636c61737365732e6f72672f67726170686963732f706870636c61737365732f696e6e6f766174696f6e2d61776172642d6c6f676f2e706e67)](https://camo.githubusercontent.com/fe57c4c057a2f4deeaef9ea59463ccb88f4fa362499336ac31c5a14bec4681a2/68747470733a2f2f66696c65732e706870636c61737365732e6f72672f67726170686963732f706870636c61737365732f696e6e6f766174696f6e2d61776172642d6c6f676f2e706e67)

PHP Innovation Award for the PHP package Hacker Earth API [Certification Link](https://www.phpclasses.org/certificate/package/10529.pdf)

Installation
------------

[](#installation)

Run this command in your terminal from your project directory:

```
composer require ankitjain28may/hackerearth-api
```

Laravel Configuration
---------------------

[](#laravel-configuration)

When the download is complete, you have to call this package service in `config/app.php` config file. To do that, add this line in `app.php` in `providers` array:

```
Ankitjain28may\HackerEarth\HackerEarthServiceProvider::class,
```

To use facade you have to add this line in `app.php` to the `aliases` array:

```
'HackerEarth' => Ankitjain28may\HackerEarth\Facades\HackerEarth::class,
```

Now run this command in your terminal to publish this package resources:

```
php artisan vendor:publish --provider="Ankitjain28may\HackerEarth\HackerEarthServiceProvider"
php artisan vendor:publish --tag=migrations

```

after publishing your config file then open `config/hackerearth.php` and add your hackerearth app key:

```
return [
    /*
    |--------------------------------------------------------------------------
    | HackerEarth API KEY
    |--------------------------------------------------------------------------
    |
    | https://api.hackerearth.com/v3/code/
    | https://api.hackerearth.com/v3/code/
    |
    */
    'api_key' => env('HACKEREARTH_SECRET_KEY', 'CLIENT_SECRET_KEY'),
];
```

also you can add api key in `.env` :

```
 HACKEREARTH_SECRET_KEY = YOUR_HACKER_EARTH_API_KEY

```

Thats it.

API List
--------

[](#api-list)

```
    $data = [
        "lang" => '',
        "source" => '',
        "input" => '',
        "async" => 0,                   // default (1 => async req and 0 => sync req)
        "callback" => '',
        'id' => '',
        'time_limit'    => 5,           // default
        'memory_limit'  => 262144,      // default
    ]
```

- Run(\[$data, ..\])
- RunFile(\[$data, ..\])
- Compile(\[$data, ..\])
- CompileFile(\[$data, ..\])

Asynchronous Request
--------------------

[](#asynchronous-request)

- Set `async = 1`.
- You need to add the callback url, Output will be returned directly to the callback url as a post request.

Synchronous Request
-------------------

[](#synchronous-request)

- Set `async = 0`.
- Output will be returned with the request's response.

For Core PHP Usage
------------------

[](#for-core-php-usage)

- create the database

```
create database [database name]

```

- import table

```
mysql -u[user] -p[password] [database name] < vendor\ankitjain28may\hackerearth-api\src\Database\migrate.sql

```

```
use Ankitjain28may\HackerEarth\HackerEarth;

$config = [
    	"api_key"     => 'hackerearth_app_key',
    ];

 $hackerearth = new HackerEarth($config);

 $data = [
    "lang" => 'php',
    "source" => ''
 ];

 $result = $hackerearth->Compile([$data]);

 var_dump($result);

 $result = $hackerearth->Run([$data]);

 var_dump($result);

 // Asynchronous

 $data = [
    "lang" => 'php',
    "source" => '',
    "async" => 1,
    "callback" => 'http://callback_url',
    "id" => 12  // Id from the db where to save or update response
 ]

 $result = $hackerearth->Run([$data]);

 vardump($result);

 // Response at Callback URL will need to save to DB with reference to the ID, Id returned is encoded using `bin2hex` which can be decoded using `hex2bin`.
```

For Laravel Usage
-----------------

[](#for-laravel-usage)

### Code Compile

[](#code-compile)

```
use Ankitjain28may\HackerEarth\Facades\HackerEarth;
use Ankitjain28may\HackerEarth\Models\Output;
//..
//..

$data = [
   "lang" => 'php',
   "source" => ''
];

$result = HackerEarth::Compile([$data, ..]);

dd($result);

// Asynchronous

$data = [
   "lang" => 'php',
   "source" => '',
   "async" => 1,
   "callback" => 'http://callback_url',
   "id" => 12  // Id from the db where to save or update response
]

$result = $hackerearth->Compile([$data]);

dd($result);

 OR

Output::saveResult(json_decode($result, True)); // Save directly to the DB

// Response at Callback URL will save to DB with reference to the ID

Output::savePayload(json_decode($_POST['payload'], True));
```

### Code Run

[](#code-run)

```
use Ankitjain28may\HackerEarth\Facades\HackerEarth;
use Ankitjain28may\HackerEarth\Models\Output;

//..
//..

$data = [
   "lang" => 'php',
   "source" => ''
];

$result = HackerEarth::Run([$data, ..]);

dd($result);

// Asynchronous

$data = [
   "lang" => 'php',
   "source" => '',
   "async" => 1,
   "callback" => 'http://callback_url',
   "id" => 12  // Id from the db where to save or update response
]

$result = $hackerearth->Run([$data]);

dd($result);

 OR

Output::saveResult(json_decode($result, True)); // Save directly to the DB

// Response at Callback URL will save to DB with reference to the ID

Output::savePayload(json_decode($_POST['payload'], True));
```

Also Compile and Run files by passing realpath of the uploaded file--
---------------------------------------------------------------------

[](#also-compile-and-run-files-by-passing-realpath-of-the-uploaded-file--)

```
use Ankitjain28may\HackerEarth\Facades\HackerEarth;

//..
//..

$data = [
   "lang" => 'php',
   "source" => realpath("test.txt")
];

$result = HackerEarth::RunFile([$data]);
$result = HackerEarth::CompileFile([$data]);
```

Contribute
----------

[](#contribute)

> Feel free to contribute

License
-------

[](#license)

> Copyright (c) 2017 Ankit Jain - Released under the MIT License

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

3233d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79b96139365daf0dd608b959d78729615f04e303e9cd665c3175356c9ec167bc?d=identicon)[ankitjain28](/maintainers/ankitjain28)

---

Top Contributors

[![ankitjain28may](https://avatars.githubusercontent.com/u/14014254?v=4)](https://github.com/ankitjain28may "ankitjain28may (26 commits)")

---

Tags

hackerearthhackerearth-apilaravellaravel-packagelaravelruncompilehackerearthhackerearth-apilaravel-hackerearth-packagecode-compilecode-run

### Embed Badge

![Health badge](/badges/ankitjain28may-hackerearth-api/health.svg)

```
[![Health](https://phpackages.com/badges/ankitjain28may-hackerearth-api/health.svg)](https://phpackages.com/packages/ankitjain28may-hackerearth-api)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[irazasyed/telegram-bot-sdk

The Unofficial Telegram Bot API PHP SDK

3.3k4.5M84](/packages/irazasyed-telegram-bot-sdk)[flat3/lodata

OData v4.01 Producer for Laravel

96320.9k](/packages/flat3-lodata)[laravel-freelancer-nl/laravel-index-now

Alert search engines of content changes.

5212.1k](/packages/laravel-freelancer-nl-laravel-index-now)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

762.6k](/packages/scriptdevelop-whatsapp-manager)

PHPackages © 2026

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