Split FPM and Swoole modes
This commit is contained in:
parent
fe400e5eac
commit
73b53cd5d9
|
@ -185,7 +185,7 @@ You can use WRK Docker image to benchmark the server performance. Benchmarking i
|
|||
```
|
||||
|
||||
```bash
|
||||
docker run --rm skandyla/wrk -t5 -c10 -d30 https://[APPWRITE_HOSTNAME_OR_IP]
|
||||
docker run --rm skandyla/wrk -t3 -c100 -d30 https://[APPWRITE_HOSTNAME_OR_IP]
|
||||
```
|
||||
|
||||
## Code Maintenance
|
||||
|
|
10
app/app.php
10
app/app.php
|
@ -297,10 +297,12 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project) {
|
|||
/** @var Utopia\View $layout */
|
||||
/** @var Appwrite\Database\Document $project */
|
||||
|
||||
var_dump(get_class($error));
|
||||
var_dump($error->getMessage());
|
||||
var_dump($error->getFile());
|
||||
var_dump($error->getLine());
|
||||
if(php_sapi_name() === 'cli') {
|
||||
var_dump(get_class($error));
|
||||
var_dump($error->getMessage());
|
||||
var_dump($error->getFile());
|
||||
var_dump($error->getLine());
|
||||
}
|
||||
|
||||
$version = App::getEnv('_APP_VERSION', 'UNKNOWN');
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
"appwrite/php-clamav": "1.0.*",
|
||||
|
||||
"utopia-php/framework": "0.8.1",
|
||||
"utopia-php/framework": "0.8.2",
|
||||
"utopia-php/abuse": "0.2.*",
|
||||
"utopia-php/audit": "0.3.*",
|
||||
"utopia-php/cache": "0.2.*",
|
||||
|
|
20
composer.lock
generated
20
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "12fa4cc8c24ef38a37424285d9be917a",
|
||||
"content-hash": "c9c02c8344b98a983e16152163f8d91a",
|
||||
"packages": [
|
||||
{
|
||||
"name": "appwrite/php-clamav",
|
||||
|
@ -1596,16 +1596,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/framework",
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/framework.git",
|
||||
"reference": "79c4193e42120b3eefcda22a0254a6bfc257d6b6"
|
||||
"reference": "7fbd96667df44f5afe30c8c48edc82a649b3c16b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/79c4193e42120b3eefcda22a0254a6bfc257d6b6",
|
||||
"reference": "79c4193e42120b3eefcda22a0254a6bfc257d6b6",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/7fbd96667df44f5afe30c8c48edc82a649b3c16b",
|
||||
"reference": "7fbd96667df44f5afe30c8c48edc82a649b3c16b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1636,7 +1636,7 @@
|
|||
"php",
|
||||
"upf"
|
||||
],
|
||||
"time": "2020-07-06T11:37:03+00:00"
|
||||
"time": "2020-07-07T04:23:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/locale",
|
||||
|
@ -3340,12 +3340,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "d190c2e7f7a0475ab86f3185ef34f958d341c5b4"
|
||||
"reference": "e063bab1a67f4ceea759cee20c10ed609d1f6abb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/d190c2e7f7a0475ab86f3185ef34f958d341c5b4",
|
||||
"reference": "d190c2e7f7a0475ab86f3185ef34f958d341c5b4",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/e063bab1a67f4ceea759cee20c10ed609d1f6abb",
|
||||
"reference": "e063bab1a67f4ceea759cee20c10ed609d1f6abb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3397,7 +3397,7 @@
|
|||
"keywords": [
|
||||
"templating"
|
||||
],
|
||||
"time": "2020-07-05T13:32:43+00:00"
|
||||
"time": "2020-07-06T13:35:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webmozart/assert",
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
* ― Rick Cook, The Wizardry Compiled
|
||||
*/
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\App;
|
||||
use Utopia\Request;
|
||||
use Utopia\Response;
|
||||
|
||||
error_reporting(0);
|
||||
ini_set('display_errors', 0);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia;
|
||||
namespace Appwrite\Swoole;
|
||||
|
||||
use Exception;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia;
|
||||
namespace Appwrite\Swoole;
|
||||
|
||||
use Utopia\Request as UtopiaRequest;
|
||||
use Swoole\Http\Request as SwooleRequest;
|
104
src/Appwrite/Swoole/Response.php
Normal file
104
src/Appwrite/Swoole/Response.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Swoole;
|
||||
|
||||
use Appwrite\Utopia\Response as UtopiaResponse;
|
||||
use Swoole\Http\Response as SwooleResponse;
|
||||
|
||||
class Response extends UtopiaResponse
|
||||
{
|
||||
/**
|
||||
* Swoole Response Object
|
||||
*
|
||||
* @var SwooleResponse
|
||||
*/
|
||||
protected $swoole = null;
|
||||
|
||||
/**
|
||||
* Response constructor.
|
||||
*/
|
||||
public function __construct(SwooleResponse $response)
|
||||
{
|
||||
$this->swoole = $response;
|
||||
parent::__construct(\microtime(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Output response
|
||||
*
|
||||
* Generate HTTP response output including the response header (+cookies) and body and prints them.
|
||||
*
|
||||
* @param string $body
|
||||
* @param int $exit exit code or don't exit if code is null
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function send(string $body = '', int $exit = null): void
|
||||
{
|
||||
if(!$this->disablePayload) {
|
||||
$this->addHeader('X-Debug-Speed', microtime(true) - $this->startTime);
|
||||
|
||||
$this
|
||||
->appendCookies()
|
||||
->appendHeaders()
|
||||
;
|
||||
|
||||
$this->size = $this->size + mb_strlen(implode("\n", $this->headers)) + mb_strlen($body, '8bit');
|
||||
|
||||
$this->swoole->end($body);
|
||||
|
||||
$this->disablePayload();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append headers
|
||||
*
|
||||
* Iterating over response headers to generate them using native PHP header function.
|
||||
* This method is also responsible for generating the response and content type headers.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function appendHeaders(): self
|
||||
{
|
||||
// Send status code header
|
||||
$this->swoole->status($this->statusCode);
|
||||
|
||||
// Send content type header
|
||||
$this
|
||||
->addHeader('Content-Type', $this->contentType)
|
||||
;
|
||||
|
||||
// Set application headers
|
||||
foreach ($this->headers as $key => $value) {
|
||||
$this->swoole->header($key, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append cookies
|
||||
*
|
||||
* Iterating over response cookies to generate them using native PHP cookie function.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function appendCookies(): self
|
||||
{
|
||||
foreach ($this->cookies as $cookie) {
|
||||
$this->swoole->cookie(
|
||||
$cookie['name'],
|
||||
$cookie['value'],
|
||||
$cookie['expire'],
|
||||
$cookie['path'],
|
||||
$cookie['domain'],
|
||||
$cookie['secure'],
|
||||
$cookie['httponly'],
|
||||
$cookie['samesite'],
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -15,7 +15,6 @@ use Appwrite\Utopia\Response\Model\Locale;
|
|||
use Appwrite\Utopia\Response\Model\Membership;
|
||||
use Appwrite\Utopia\Response\Model\MembershipList;
|
||||
use Utopia\Response as UtopiaResponse;
|
||||
use Swoole\Http\Response as SwooleResponse;
|
||||
|
||||
class Response extends UtopiaResponse
|
||||
{
|
||||
|
@ -51,19 +50,11 @@ class Response extends UtopiaResponse
|
|||
const MODEL_MEMBERSHIP = 'membership';
|
||||
const MODEL_MEMBERSHIP_LIST = 'membershipList';
|
||||
|
||||
/**
|
||||
* Swoole Response Object
|
||||
*
|
||||
* @var SwooleResponse
|
||||
*/
|
||||
protected $swoole = null;
|
||||
|
||||
/**
|
||||
* Response constructor.
|
||||
*/
|
||||
public function __construct(SwooleResponse $response)
|
||||
public function __construct(int $time = 0)
|
||||
{
|
||||
$this->swoole = $response;
|
||||
$this
|
||||
->setModel(new Error())
|
||||
->setModel(new ErrorDev())
|
||||
|
@ -76,7 +67,7 @@ class Response extends UtopiaResponse
|
|||
->setModel(new MembershipList())
|
||||
;
|
||||
|
||||
$this->startTime = \microtime(true);
|
||||
parent::__construct($time);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -182,83 +173,4 @@ class Response extends UtopiaResponse
|
|||
->send(yaml_emit($data, YAML_UTF8_ENCODING))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output response
|
||||
*
|
||||
* Generate HTTP response output including the response header (+cookies) and body and prints them.
|
||||
*
|
||||
* @param string $body
|
||||
* @param int $exit exit code or don't exit if code is null
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function send(string $body = '', int $exit = null): void
|
||||
{
|
||||
if(!$this->disablePayload) {
|
||||
$this->addHeader('X-Debug-Speed', microtime(true) - $this->startTime);
|
||||
|
||||
$this
|
||||
->appendCookies()
|
||||
->appendHeaders()
|
||||
;
|
||||
|
||||
$this->size = $this->size + mb_strlen(implode("\n", $this->headers)) + mb_strlen($body, '8bit');
|
||||
|
||||
$this->swoole->end($body);
|
||||
|
||||
$this->disablePayload();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append headers
|
||||
*
|
||||
* Iterating over response headers to generate them using native PHP header function.
|
||||
* This method is also responsible for generating the response and content type headers.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function appendHeaders(): self
|
||||
{
|
||||
// Send status code header
|
||||
$this->swoole->status($this->statusCode);
|
||||
|
||||
// Send content type header
|
||||
$this
|
||||
->addHeader('Content-Type', $this->contentType)
|
||||
;
|
||||
|
||||
// Set application headers
|
||||
foreach ($this->headers as $key => $value) {
|
||||
$this->swoole->header($key, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append cookies
|
||||
*
|
||||
* Iterating over response cookies to generate them using native PHP cookie function.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function appendCookies(): self
|
||||
{
|
||||
foreach ($this->cookies as $cookie) {
|
||||
$this->swoole->cookie(
|
||||
$cookie['name'],
|
||||
$cookie['value'],
|
||||
$cookie['expire'],
|
||||
$cookie['path'],
|
||||
$cookie['domain'],
|
||||
$cookie['secure'],
|
||||
$cookie['httponly'],
|
||||
$cookie['samesite'],
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Appwrite\URL\URL;
|
||||
use Appwrite\Utopia\Files;
|
||||
use Appwrite\Swoole\Files;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FilesTest extends TestCase
|
Loading…
Reference in a new issue