PHPackages                             xefreh/judge0-php-client - 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. xefreh/judge0-php-client

ActiveLibrary[API Development](/categories/api)

xefreh/judge0-php-client
========================

PHP Client for Judge0 API

11321PHP

Since Jan 13Pushed 3mo agoCompare

[ Source](https://github.com/Xefreh/judge0-php-client)[ Packagist](https://packagist.org/packages/xefreh/judge0-php-client)[ RSS](/packages/xefreh-judge0-php-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Judge0 PHP Client
=================

[](#judge0-php-client)

A PHP client library for the [Judge0](https://judge0.com) API - an online code execution system that supports 60+ programming languages.

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- Composer
- ext-zip (for multi-file submissions)

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

[](#installation)

```
composer require xefreh/judge0-php-client
```

Quick Start
-----------

[](#quick-start)

```
use Xefreh\Judge0PhpClient\Judge0Client;
use Xefreh\Judge0PhpClient\DTO\Submission;

$client = new Judge0Client(
    apiHost: 'judge0-ce.p.rapidapi.com',
    apiKey: 'your-api-key',
);

// Execute Python code
$submission = new Submission(
    languageId: 71, // Python 3.8.1
    sourceCode: 'print("Hello, World!")',
);

$result = $client->submissions->create($submission);
$final = $client->submissions->wait($result->token);

echo $final->stdout; // "Hello, World!"
```

Configuration
-------------

[](#configuration)

### Constructor Parameters

[](#constructor-parameters)

ParameterTypeRequiredDescription`apiHost`stringYesJudge0 API host (e.g., `judge0-ce.p.rapidapi.com`)`apiKey`stringYesAPI key for authentication`cache`CacheInterfaceNoCache instance for reducing API calls### Caching

[](#caching)

Enable in-memory caching to reduce API calls:

```
use Xefreh\Judge0PhpClient\Cache\ArrayCache;

$client = new Judge0Client(
    apiHost: 'judge0-ce.p.rapidapi.com',
    apiKey: 'your-api-key',
    cache: new ArrayCache(),
);

// Clear cache when needed
$client->clearCache();
```

**Cache TTLs:**

- Languages &amp; Statuses: 24 hours
- About &amp; Config: 1 hour
- Completed submission results: 24 hours

API Reference
-------------

[](#api-reference)

### Languages

[](#languages)

```
// Get all available languages
$languages = $client->languages->all();

// Get a specific language
$python = $client->languages->get(71);
echo $python->name; // "Python (3.8.1)"
```

### Submissions

[](#submissions)

```
use Xefreh\Judge0PhpClient\DTO\Submission;

// Create a submission
$submission = new Submission(
    languageId: 71,
    sourceCode: 'print(input())',
    stdin: 'Hello',
);

// Async submission (returns immediately with token)
$result = $client->submissions->create($submission);

// Sync submission (waits for result)
$result = $client->submissions->create($submission, wait: true);

// Get submission by token
$result = $client->submissions->get($token);

// Wait for submission to complete (polling)
$result = $client->submissions->wait($token, maxAttempts: 30, intervalMs: 1000);

// Batch submissions
$results = $client->submissions->createBatch([$submission1, $submission2]);
$results = $client->submissions->getBatch(['token1', 'token2']);
```

### Submission Options

[](#submission-options)

```
$submission = new Submission(
    languageId: 71,
    sourceCode: 'print("Hello")',
    stdin: 'input data',
    expectedOutput: 'Hello',
    cpuTimeLimit: 5.0,
    cpuExtraTime: 1.0,
    wallTimeLimit: 10.0,
    memoryLimit: 128000,
    stackLimit: 64000,
    compilerOptions: '-O2',
    commandLineArguments: '--verbose',
    callbackUrl: 'https://example.com/callback',
    redirectStderrToStdout: false,
);
```

### Multi-file Programs

[](#multi-file-programs)

For projects with multiple files (e.g., C++ with CMake), use the `ArchiveBuilder` utility to create a base64-encoded zip archive:

```
use Xefreh\Judge0PhpClient\Utils\ArchiveBuilder;
use Xefreh\Judge0PhpClient\DTO\Submission;

// From string contents
$archive = ArchiveBuilder::createArchive(
    files: [
        'main.cpp' => '#include \nint main() { std::cout
