Skip to content

nesk/network.js-php-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP server for Network.js

A server implementation written in PHP for Network.js. Available as a standalone archive or as a library based on the PSR-7 standard.

Usage

As a standalone project

Download an archive and extract it wherever you want on your web server. Then, in the client configuration, specify the path to the index.php file:

new Network({
    endpoint: 'path/to/the/server/directory/index.php'
});

As a library

Since this project is based on the PSR-7 standard, you can use it in “vanilla PHP”, Symfony, Laravel, etc…

composer require network-js/php-server

You can use the NetworkJs\ResponseFactory class to generate responses:

use NetworkJs\ResponseFactory;

The fromRequest method returns a response based on the "module" and "size" query parameters written in the PSR-7 request you provide (if you omit this parameter, a default request will be generated). It is also recommended to provide a maximum size (in bytes) for the download response, it avoids to overload your server if a client asks for a very big size.

$response = ResponseFactory::fromRequest(
    $request, // An object implementing `Psr\Http\Message\ServerRequestInterface`
    1024 * 1024 * 512 // A maximum size of 512MB
);

The fromValues method is nearly the same as fromRequest but you manually provide the module name (latency, upload or download) and the size (in bytes).

$response = ResponseFactory::fromValues(
    'download',
    1024 * 1024 * 50, // A size of 50MB
    1024 * 1024 * 512 // A maximum size of 512MB
);

The returned object is a child instance of the NetworkJs\Response class, which provides a send method.

$response->send();

Sidenote for non-Apache users

This server implementation is configured to disable GZIP compression when Apache is used but not with other web servers. You MUST disable this feature for the endpoints used by Network.js or the measures will fail!

License

This project is licensed under the MIT license, check TLDRLegal for details.

About

A PHP server implementation for Network.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages