PHPackages                             daijie/aria2 - 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. daijie/aria2

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

daijie/aria2
============

talk with aria2

v1.2.1b(9y ago)736.8k27WTFPLPHPPHP &gt;=5.4.0

Since Jun 22Pushed 2y ago2 watchersCompare

[ Source](https://github.com/shiny/php-aria2)[ Packagist](https://packagist.org/packages/daijie/aria2)[ Docs](https://github.com/shiny/php-aria2)[ RSS](/packages/daijie-aria2/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

php-aria2
=========

[](#php-aria2)

Talking with [aria2](https://aria2.github.io/) through JSON-RPC

1. [Install](#install)
2. [Class Aria2](#class-aria2)
    1. [Usage](#usage)
    2. [Batch Requests](#batch-requests)
    3. [System Methods](#system-methods)
    4. [Example #1: Download File](#example-1-download-file)
    5. [Example #2: The Returned Data](#example-2-the-returned-data)
        1. [Can't Download](#case-cant-download)
        2. [Downloading (Active)](#case-downloading-active)
        3. [Downloaded](#case-downloaded)
3. [Docker Playground](#docker-playground)
4. [Updates](#updates)
5. [Contributors](#contributors)

Install
-------

[](#install)

### 1. [Install aria2c](https://aria2.github.io/)

[](#1-install-aria2c)

Make sure aria2c is running and rpc is enabled, You can add this into /etc/rc.local `/usr/local/bin/aria2c --enable-rpc --rpc-allow-origin-all -c -D`

> [Also See The Document of Aria2](https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface)

### 2. Require Aria2.php

[](#2-require-aria2php)

The codes just 82 lines but support all RPC methods. Using php's magic method `__call`

#### 2.1 Install by composer

[](#21-install-by-composer)

`composer require daijie/aria2`

#### 2.2 Or copy Aria2.php

[](#22-or-copy-aria2php)

Class Aria2
-----------

[](#class-aria2)

```
Aria2 {
    __construct ( string $server [, string $token ] )
    __destruct ( void )
    __call(string $name, array $arg)
    public Object batch( [Callable $func ] )
    public bool inBatch( void )
    public array commit( void )
    protected string req ( array $data )
}
```

Usage
-----

[](#usage)

```
$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');
// http://127.0.0.1:6800/jsonrpc is the default value,
// equals to $aria2 = new Aria2
$aria2->getGlobalStat();
$aria2->tellActive();
$aria2->tellWaiting(0,1000);
$aria2->tellStopped(0,1000);
$aria2->addUri(
	['https://www.google.com.hk/images/srpr/logo3w.png'],
	['dir'=>'/tmp']
);
$aria2->tellStatus('1');
$aria2->removeDownloadResult('1');
//and more ...
```

#### Also See [Manual of Aria2 RPC Interface To Get The Method List](https://aria2.github.io/manual/en/html/aria2c.html#methods)

[](#also-see--manual-of-aria2-rpc-interface-to-get-the-method-list)

> .i.e, It's the example from Aria2 manual wrote in Python:

```
>>> import urllib2, json, base64
>>> metalink = base64.b64encode(open('file.meta4').read())
>>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer',
...                       'method':'aria2.addMetalink',
...                       'params':[metalink]})
>>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq)
>>> c.read()
'{"id":"qwer","jsonrpc":"2.0","result":["2089b05ecca3d829"]}'
```

If you are using php with php-aria2:

```
