Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/utopia-php/swoole

An extension for Utopia Framework to work with PHP Swoole as a PHP FPM alternative
https://github.com/utopia-php/swoole

hacktoberfest php swoole utopia-framework

Last synced: 10 days ago
JSON representation

An extension for Utopia Framework to work with PHP Swoole as a PHP FPM alternative

Lists

README

        

# Utopia Swoole

[![Build Status](https://travis-ci.com/utopia-php/swoole.svg?branch=master)](https://travis-ci.com/utopia-php/swoole)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://appwrite.io/discord)
![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/swoole.svg)

An extension for Utopia Framework to work with [PHP Swoole](https://github.com/swoole/swoole-src) as a PHP FPM alternative. This library extends the default Utopia Request & Response classes with ones that can interact with the Swoole server. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).

This library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project. Your PHP installation should be compiled with the [PHP Swoole](https://github.com/swoole/swoole-src) extension for this library to work with Utopia PHP.

## Getting Started

Install using composer:
```bash
composer require utopia-php/swoole
```

```php
on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) {
$request = new Request($swooleRequest);
$response = new Response($swooleResponse);

if(Files::isFileLoaded($request->getURI())) { // output static files with cache headers
$time = (60 * 60 * 24 * 365 * 2); // 45 days cache

$response
->setContentType(Files::getFileMimeType($request->getURI()))
->addHeader('Cache-Control', 'public, max-age='.$time)
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache
->send(Files::getFileContents($request->getURI()))
;

return;
}

$app = new App('Asia/Tel_Aviv');

try {
$app->run($request, $response);
} catch (\Throwable $th) {
$swooleResponse->end('500: Server Error');
}
});

$http->start();

```

## System Requirements

Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.

## Copyright and license

The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)