mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Added PHP preload support
This commit is contained in:
+12
-8
@@ -100,14 +100,6 @@ RUN \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set Upload Limit (default to 100MB)
|
||||
RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
|
||||
RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
|
||||
RUN echo "env[TESTME] = your-secret-key" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
|
||||
|
||||
# Add logs file
|
||||
RUN echo "" >> /var/log/appwrite.log
|
||||
|
||||
# Nginx Configuration (with self-signed ssl certificates)
|
||||
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY ./docker/ssl/cert.pem /etc/nginx/ssl/cert.pem
|
||||
@@ -136,6 +128,18 @@ RUN mkdir -p /storage/uploads && \
|
||||
# Supervisord Conf
|
||||
COPY ./docker/supervisord.conf /etc/supervisord.conf
|
||||
|
||||
# Set Upload Limit (default to 100MB)
|
||||
RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
|
||||
RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
|
||||
RUN echo "env[TESTME] = your-secret-key" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
|
||||
RUN echo "opcache.preload_user=www-data" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
|
||||
RUN echo "opcache.preload=/usr/share/nginx/html/app/preload.php" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
|
||||
RUN echo "opcache.preload_user=www-data" >> /etc/php/$PHP_VERSION/cli/conf.d/appwrite.ini
|
||||
RUN echo "opcache.preload=/usr/share/nginx/html/app/preload.php" >> /etc/php/$PHP_VERSION/cli/conf.d/appwrite.ini
|
||||
|
||||
# Add logs file
|
||||
RUN echo "" >> /var/log/appwrite.log
|
||||
|
||||
# Start
|
||||
COPY ./docker/bin/start /start
|
||||
RUN chmod 775 /start
|
||||
|
||||
@@ -150,7 +150,6 @@ $utopia->get('/v1/locale/continents')
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$utopia->get('/v1/locale/currencies')
|
||||
->desc('List Currencies')
|
||||
->label('scope', 'locale.read')
|
||||
|
||||
@@ -22,7 +22,7 @@ if (!empty($request->getQuery('version', ''))) {
|
||||
$layout
|
||||
->setParam('title', APP_NAME)
|
||||
->setParam('protocol', Config::getParam('protocol'))
|
||||
->setParam('domain', $domain)
|
||||
->setParam('domain', Config::getParam('domain'))
|
||||
->setParam('home', $request->getServer('_APP_HOME'))
|
||||
->setParam('setup', $request->getServer('_APP_SETUP'))
|
||||
->setParam('class', 'unknown')
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Init
|
||||
*
|
||||
* Inializes both Appwrite API entry point, queue workers, and CLI tasks.
|
||||
* Set configuration, framework resources, app constants
|
||||
*
|
||||
*/
|
||||
|
||||
// ini_set('display_errors', 1);
|
||||
// ini_set('display_startup_errors', 1);
|
||||
// error_reporting(E_ALL);
|
||||
|
||||
if (file_exists(__DIR__.'/../vendor/autoload.php')) {
|
||||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
}
|
||||
|
||||
require_once 'init.php';
|
||||
|
||||
require_once __DIR__ . '/config/collections.php';
|
||||
require_once __DIR__ . '/config/currencies.php';
|
||||
require_once __DIR__ . '/config/eu.php';
|
||||
require_once __DIR__ . '/config/locales.php';
|
||||
require_once __DIR__ . '/config/phones.php';
|
||||
require_once __DIR__ . '/config/platforms.php';
|
||||
require_once __DIR__ . '/config/providers.php';
|
||||
require_once __DIR__ . '/config/roles.php';
|
||||
require_once __DIR__ . '/config/scopes.php';
|
||||
require_once __DIR__ . '/config/services.php';
|
||||
|
||||
require_once __DIR__ . '/controllers/web/console.php';
|
||||
require_once __DIR__ . '/controllers/web/home.php';
|
||||
require_once __DIR__ . '/controllers/api/account.php';
|
||||
require_once __DIR__ . '/controllers/api/avatars.php';
|
||||
require_once __DIR__ . '/controllers/api/database.php';
|
||||
require_once __DIR__ . '/controllers/api/graphql.php';
|
||||
require_once __DIR__ . '/controllers/api/health.php';
|
||||
require_once __DIR__ . '/controllers/api/locale.php';
|
||||
require_once __DIR__ . '/controllers/api/projects.php';
|
||||
require_once __DIR__ . '/controllers/api/storage.php';
|
||||
require_once __DIR__ . '/controllers/api/teams.php';
|
||||
require_once __DIR__ . '/controllers/api/users.php';
|
||||
|
||||
// use Appwrite\Preloader\Preloader;
|
||||
// (new Preloader())
|
||||
// ->paths(realpath(__DIR__ . '/../vendor'))
|
||||
// //->paths(realpath(__DIR__ . '/config'))
|
||||
// // ->ignore(
|
||||
// // \Illuminate\Filesystem\Cache::class,
|
||||
// // \Illuminate\Log\LogManager::class,
|
||||
// // \Illuminate\Http\Testing\File::class,
|
||||
// // \Illuminate\Http\UploadedFile::class,
|
||||
// // \Illuminate\Support\Carbon::class,
|
||||
// // )
|
||||
// ->load();
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Preloader;
|
||||
|
||||
class Preloader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $ignores = [];
|
||||
|
||||
private static $count = 0;
|
||||
|
||||
private $paths;
|
||||
|
||||
private $fileMap;
|
||||
|
||||
public function __construct(string ...$paths)
|
||||
{
|
||||
$this->paths = $paths;
|
||||
|
||||
// We'll use composer's classmap
|
||||
// to easily find which classes to autoload,
|
||||
// based on their filename
|
||||
$classMap = require __DIR__ . '/../../../vendor/composer/autoload_classmap.php';
|
||||
|
||||
$this->fileMap = array_flip($classMap);
|
||||
}
|
||||
|
||||
public function paths(string ...$paths): Preloader
|
||||
{
|
||||
$this->paths = array_merge(
|
||||
$this->paths,
|
||||
$paths
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function ignore(string ...$names): Preloader
|
||||
{
|
||||
$this->ignores = array_merge(
|
||||
$this->ignores,
|
||||
$names
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function load(): void
|
||||
{
|
||||
// We'll loop over all registered paths
|
||||
// and load them one by one
|
||||
foreach ($this->paths as $path) {
|
||||
$this->loadPath(rtrim($path, '/'));
|
||||
}
|
||||
|
||||
$count = self::$count;
|
||||
|
||||
echo "[Preloader] Preloaded {$count} classes" . PHP_EOL;
|
||||
}
|
||||
|
||||
private function loadPath(string $path): void
|
||||
{
|
||||
// If the current path is a directory,
|
||||
// we'll load all files in it
|
||||
if (is_dir($path)) {
|
||||
$this->loadDir($path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise we'll just load this one file
|
||||
$this->loadFile($path);
|
||||
}
|
||||
|
||||
private function loadDir(string $path): void
|
||||
{
|
||||
$handle = opendir($path);
|
||||
|
||||
// We'll loop over all files and directories
|
||||
// in the current path,
|
||||
// and load them one by one
|
||||
while ($file = readdir($handle)) {
|
||||
if (in_array($file, ['.', '..'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->loadPath("{$path}/{$file}");
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
private function loadFile(string $path): void
|
||||
{
|
||||
// We resolve the classname from composer's autoload mapping
|
||||
$class = $this->fileMap[$path] ?? null;
|
||||
|
||||
// And use it to make sure the class shouldn't be ignored
|
||||
if ($this->shouldIgnore($class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Finally we require the path,
|
||||
// causing all its dependencies to be loaded as well
|
||||
require_once($path);
|
||||
|
||||
self::$count++;
|
||||
|
||||
echo "[Preloader] Preloaded `{$class}`" . PHP_EOL;
|
||||
}
|
||||
|
||||
private function shouldIgnore(?string $name): bool
|
||||
{
|
||||
if ($name === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->ignores as $ignore) {
|
||||
if (strpos($name, $ignore) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class S3 extends Device
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName():string
|
||||
{
|
||||
return 'S3 Storage';
|
||||
}
|
||||
@@ -17,7 +17,7 @@ class S3 extends Device
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
public function getDescription():string
|
||||
{
|
||||
return 'S3 Bucket Storage drive for AWS or on premise solution';
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class S3 extends Device
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoot()
|
||||
public function getRoot():string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@@ -35,14 +35,162 @@ class S3 extends Device
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath($filename)
|
||||
public function getPath($filename):string
|
||||
{
|
||||
$path = '';
|
||||
|
||||
for ($i = 0; $i < 4; ++$i) {
|
||||
$path = ($i < strlen($filename)) ? $path.DIRECTORY_SEPARATOR.$filename[$i] : $path.DIRECTORY_SEPARATOR.'x';
|
||||
}
|
||||
|
||||
return $this->getRoot().$path.DIRECTORY_SEPARATOR.$filename;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload.
|
||||
*
|
||||
* Upload a file to desired destination in the selected disk.
|
||||
*
|
||||
* @param string $target
|
||||
* @param string $filename
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return string|bool saved destination on success or false on failures
|
||||
*/
|
||||
public function upload($source, $path):bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read file by given path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read(string $path):string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Write file by given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write(string $path, string $data):bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move file from given source to given path, Return true on success and false on failure.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.filesize.php
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $target
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function move(string $source, string $target):bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete file in given path, Return true on success and false on failure.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.filesize.php
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(string $path):bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns given file path its size.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.filesize.php
|
||||
*
|
||||
* @param $path
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getFileSize(string $path):int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns given file path its mime type.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.mime-content-type.php
|
||||
*
|
||||
* @param $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileMimeType(string $path):string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns given file path its MD5 hash value.
|
||||
*
|
||||
* @see http://php.net/manual/en/function.md5-file.php
|
||||
*
|
||||
* @param $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileHash(string $path):string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get directory size in bytes.
|
||||
*
|
||||
* Return -1 on error
|
||||
*
|
||||
* Based on http://www.jonasjohn.de/snippets/php/dir-size.htm
|
||||
*
|
||||
* @param $path
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDirectorySize(string $path):int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Partition Free Space.
|
||||
*
|
||||
* disk_free_space — Returns available space on filesystem or disk partition
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPartitionFreeSpace():float
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Partition Total Space.
|
||||
*
|
||||
* disk_total_space — Returns the total size of a filesystem or disk partition
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPartitionTotalSpace():float
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user