-
Notifications
You must be signed in to change notification settings - Fork 2k
Fomo framework for PHP #9584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fomo framework for PHP #9584
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5e4b2a9
added fomo framework
n0nag0n fec3f6e
added some .keep files
n0nag0n 3a07787
corrected readme
n0nag0n d2e39f4
Update .env remove APP_WORKER_COUNT
joanhey d980606
Test with PHP8.4
joanhey 5aa559e
Revert to PHP8.3
joanhey 66c0d21
Remove unnece
joanhey 051603e
Remove unnecessary services configs
joanhey 7a1b538
Merge pull request #1 from joanhey/patch-9
n0nag0n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| APP_NAME=Fomo | ||
| APP_TIMEZONE=UTC | ||
| APP_WORKER_COUNT=8 | ||
| APP_ENV=local | ||
| APP_SSL=false | ||
| APP_DEBUG=false | ||
| APP_URL=http://localhost | ||
|
|
||
| DB_HOST=tfb-database | ||
| DB_PORT=3306 | ||
| DB_DATABASE=hello_world | ||
| DB_USERNAME=benchmarkdbuser | ||
| DB_PASSWORD=benchmarkdbpass | ||
| DB_CHARSET=utf8mb4 | ||
| DB_COLLATION=utf8mb4_unicode_ci | ||
|
|
||
| REDIS_HOST=127.0.0.1 | ||
| REDIS_PASSWORD=null | ||
| REDIS_USERNAME=null | ||
| REDIS_PORT=6379 | ||
| REDIS_DATABASE=0 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| .buildpath | ||
| .settings/ | ||
| .project | ||
| *.patch | ||
| .idea/ | ||
| .git/ | ||
| runtime/ | ||
| vendor/ | ||
| .phpintel/ | ||
| .DS_Store | ||
| *.lock | ||
| .phpunit* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Introduction | ||
|
|
||
| Fomo is a web application framework based. | ||
|
|
||
| We tried to implement Fomo in the simplest possible way so that anyone can use it. | ||
|
|
||
| Fomo supports the following: | ||
|
|
||
| - Simple, fast routing engine. | ||
| - Processing work in the background. | ||
| - Queued job processing. | ||
| - And more... | ||
|
|
||
| Fomo is very fast, simple and for use in large scale projects. | ||
|
|
||
| # Original intention | ||
|
|
||
| Here's 3 reason why you should use Fomo: | ||
|
|
||
| - Fomo is very simple (less to learn and train others on). | ||
| - Fomo is very fast (uses fewer resources to do the same thing). | ||
| - Fomo is another tool that developers can use to solve their complex problems in a simple way. | ||
|
|
||
| # Documentation | ||
|
|
||
| [https://fomo-framework.github.io/docs/](https://fomo-framework.github.io/docs/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Fomo\Request\Request; | ||
| use Throwable; | ||
|
|
||
| class Handler | ||
| { | ||
| public function notFoundHttpException(Request $request): string | ||
| { | ||
| return response()->json([ | ||
| 'message' => 'not found' | ||
| ] , 404); | ||
| } | ||
|
|
||
| public function notAllowedHttpException(Request $request): string | ||
| { | ||
| return response()->json([ | ||
| 'message' => "this is route supported {$request->method()} method" | ||
| ] , 405); | ||
| } | ||
|
|
||
| public function InternalErrorException(Request $request, Throwable $error): string | ||
| { | ||
| return response()->json([ | ||
| 'message' => 'internal error' | ||
| ] , 500); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "framework": "fomo", | ||
| "tests": [ | ||
| { | ||
| "default": { | ||
| "json_url": "/json", | ||
| "plaintext_url": "/plaintext", | ||
| "db_url": "/db", | ||
| "fortune_url": "/fortunes", | ||
| "query_url": "/query?queries=", | ||
| "update_url": "/update?queries=", | ||
| "port": 9000, | ||
| "approach": "Realistic", | ||
| "classification": "Micro", | ||
| "database": "mysql", | ||
| "framework": "Fomo", | ||
| "language": "PHP", | ||
| "flavor": "None", | ||
| "orm": "Full", | ||
| "platform": "swoole", | ||
| "webserver": "None", | ||
| "os": "Linux", | ||
| "database_os": "Linux", | ||
| "display_name": "Fomo", | ||
| "notes": "", | ||
| "versus": "swoole" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "name": "fomo/fomo", | ||
| "description": "The Fomo Framework", | ||
| "keywords": ["framework", "fomo" , "high performance"], | ||
| "type": "project", | ||
| "license": "MIT", | ||
| "authors": [ | ||
| { | ||
| "name": "Amir", | ||
| "email": "[email protected]" | ||
| } | ||
| ], | ||
| "require": { | ||
| "php" : ">=8.1", | ||
| "fomo/framework": "^2.0" | ||
| }, | ||
| "autoload": { | ||
| "psr-4": { | ||
| "App\\" : "app/" , | ||
| "Database\\" : "database/", | ||
| "Storage\\Routes\\" : "storage/routes/" | ||
| } | ||
| }, | ||
| "autoload-dev": { | ||
| "psr-4": { | ||
| "Tests\\": "tests/" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "post-root-package-install": [ | ||
| "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" | ||
| ] | ||
| }, | ||
| "minimum-stability": "dev", | ||
| "prefer-stable": true, | ||
| "require-dev": { | ||
| "fakerphp/faker": "^1.15", | ||
| "phpunit/phpunit": "^9.5" | ||
| }, | ||
| "config": { | ||
| "allow-plugins": { | ||
| "php-http/discovery": true | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| [framework] | ||
| name = "fomo" | ||
|
|
||
| [main] | ||
| urls.plaintext = "/plaintext" | ||
| urls.json = "/json" | ||
| urls.db = "/db" | ||
| urls.query = "/queries/" | ||
| urls.update = "/updates/" | ||
| urls.fortune = "/fortunes" | ||
| approach = "Realistic" | ||
| classification = "Fullstack" | ||
| database = "MySQL" | ||
| database_os = "Linux" | ||
| os = "Linux" | ||
| orm = "Full" | ||
| platform = "swoole" | ||
| webserver = "None" | ||
| versus = "swoole" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'name' => env('APP_NAME' , 'Fomo'), | ||
| 'timezone' => env('APP_TIMEZONE' , 'UTC'), | ||
| 'faker_locale' => 'en_US' , | ||
| 'locale' => 'en' , | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'default' => env('DB_CONNECTION', 'mysql'), | ||
|
|
||
| 'connections' => [ | ||
|
|
||
| 'sqlite' => [ | ||
| 'driver' => 'sqlite', | ||
| 'url' => env('DATABASE_URL'), | ||
| 'database' => env('DB_DATABASE', databasePath('database.sqlite')), | ||
| 'prefix' => '', | ||
| 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), | ||
| ], | ||
|
|
||
| 'mysql' => [ | ||
| 'driver' => 'mysql', | ||
| 'url' => env('DATABASE_URL'), | ||
| 'host' => env('DB_HOST', '127.0.0.1'), | ||
| 'port' => env('DB_PORT', '3306'), | ||
| 'database' => env('DB_DATABASE', 'forge'), | ||
| 'username' => env('DB_USERNAME', 'forge'), | ||
| 'password' => env('DB_PASSWORD', ''), | ||
| 'unix_socket' => env('DB_SOCKET', ''), | ||
| 'charset' => 'utf8mb4', | ||
| 'collation' => 'utf8mb4_unicode_ci', | ||
| 'prefix' => '', | ||
| 'prefix_indexes' => true, | ||
| 'strict' => true, | ||
| 'engine' => null, | ||
| 'options' => extension_loaded('pdo_mysql') ? array_filter([ | ||
| PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), | ||
| ]) : [], | ||
| ], | ||
|
|
||
| 'pgsql' => [ | ||
| 'driver' => 'pgsql', | ||
| 'url' => env('DATABASE_URL'), | ||
| 'host' => env('DB_HOST', '127.0.0.1'), | ||
| 'port' => env('DB_PORT', '5432'), | ||
| 'database' => env('DB_DATABASE', 'forge'), | ||
| 'username' => env('DB_USERNAME', 'forge'), | ||
| 'password' => env('DB_PASSWORD', ''), | ||
| 'charset' => 'utf8', | ||
| 'prefix' => '', | ||
| 'prefix_indexes' => true, | ||
| 'search_path' => 'public', | ||
| 'sslmode' => 'prefer', | ||
| ], | ||
|
|
||
| 'sqlsrv' => [ | ||
| 'driver' => 'sqlsrv', | ||
| 'url' => env('DATABASE_URL'), | ||
| 'host' => env('DB_HOST', 'localhost'), | ||
| 'port' => env('DB_PORT', '1433'), | ||
| 'database' => env('DB_DATABASE', 'forge'), | ||
| 'username' => env('DB_USERNAME', 'forge'), | ||
| 'password' => env('DB_PASSWORD', ''), | ||
| 'charset' => 'utf8', | ||
| 'prefix' => '', | ||
| 'prefix_indexes' => true, | ||
| // 'encrypt' => env('DB_ENCRYPT', 'yes'), | ||
| // 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'), | ||
| ], | ||
|
|
||
| ] | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'host' => env('ELASTICSEARCH_HOST' , '127.0.0.1'), | ||
| 'port' => env('ELASTICSEARCH_PORT' , 9200), | ||
| 'username' => env('ELASTICSEARCH_USERNAME'), | ||
| 'password' => env('ELASTICSEARCH_PASSWORD') | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'host' => env('MAIL_HOST' , 'smtp.mailtrap.io'), | ||
| 'username' => env('MAIL_USERNAME'), | ||
| 'password' => env('MAIL_PASSWORD'), | ||
| 'port' => env('MAIL_PORT' , 2525) | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'host' => env('REDIS_HOST' , '127.0.0.1'), | ||
| 'username' => env('REDIS_USERNAME'), | ||
| 'password' => env('REDIS_PASSWORD'), | ||
| 'port' => env('REDIS_PORT' , 6379), | ||
| 'database' => env('REDIS_DATABASE' , 0), | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| /* | ||
| * mode | ||
| * SWOOLE_BASE , | ||
| * SWOOLE_PROCESS | ||
| */ | ||
| 'mode' => SWOOLE_BASE , | ||
| 'host' => '0.0.0.0', | ||
| 'port' => 9000 , | ||
| 'sockType' => SWOOLE_SOCK_TCP , | ||
| 'additional' => [ | ||
| 'worker_num' => env('APP_WORKER_COUNT' , cpuCount() * 2) , | ||
| /* | ||
| * log level | ||
| * SWOOLE_LOG_DEBUG (default) | ||
| * SWOOLE_LOG_TRACE | ||
| * SWOOLE_LOG_INFO | ||
| * SWOOLE_LOG_NOTICE | ||
| * SWOOLE_LOG_WARNING | ||
| * SWOOLE_LOG_ERROR | ||
| */ | ||
| 'log_level' => SWOOLE_LOG_DEBUG , | ||
| 'log_file' => storagePath('logs/fomo.log') , | ||
|
|
||
| /* | ||
| This key causes Fomo to receive a complete HTTP data packet and prevents it from receiving incomplete HTTP packets. | ||
| */ | ||
| 'open_http_protocol' => true, | ||
| ], | ||
|
|
||
| 'ssl' => [ | ||
| 'ssl_cert_file' => null , | ||
| 'ssl_key_file' => null , | ||
| ] , | ||
|
|
||
| /* | ||
| * The following services are created for better performance in the program, only one object is created from them and they can be used throughout the program | ||
| */ | ||
| 'services' => [ | ||
| Fomo\Services\Auth::class , | ||
| Fomo\Services\Cache::class , | ||
| Fomo\Services\Database::class , | ||
| Fomo\Services\Elasticsearch::class , | ||
| Fomo\Services\Language::class , | ||
| Fomo\Services\Mail::class , | ||
| Fomo\Services\Redis::class , | ||
| Fomo\Services\Response::class , | ||
| Fomo\Services\Validation::class , | ||
|
||
| ] , | ||
|
|
||
| /* | ||
| * Files and folders that must be changed in real time | ||
| */ | ||
| 'watcher' => [ | ||
| 'app', | ||
| 'config', | ||
| 'database', | ||
| 'language', | ||
| 'routes', | ||
| 'composer.lock', | ||
| '.env', | ||
| ] , | ||
|
|
||
| /* | ||
| * Each of the following causes changes to the performance of the desired class. (so be careful in using them) | ||
| */ | ||
| 'advanceMode' => [ | ||
| /* | ||
| * advanced mode in Fomo\Request\Request class | ||
| * | ||
| * By activating the advanced mode in this class, you can access the data you want in an advanced way | ||
| * For example, consider that the user has sent you a array of the information of several customers. | ||
| * If the advanced mode is not active, you can only access an array of all customer information | ||
| * | ||
| * For example, the: | ||
| * $request->get('customers') | ||
| * | ||
| * But if the advanced mode is active, you can access any data you need from customers | ||
| * For example, the: | ||
| * $request->get('customers.*.name') | ||
| */ | ||
| 'request' => DISABLE | ||
| ] | ||
| ]; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete
APP_WORKER_COUNT, so the server will adapt dynamically to the computer CPUs.The bench run with different servers machines, the citrine actually with 28 cores and 56 threads.
In server.php
✋ @n0nag0n