
Présentation
Qu'est-ce que Swoft?
Swoft est un framework de coroutine de microservices hautes performances PHP. Il est publié depuis de nombreuses années et est devenu le meilleur choix pour php. Il peut être comme Go, serveur Web coroutine intégré et client coroutine commun et réside en mémoire, indépendamment du PHP-FPM traditionnel. Il existe des opérations de langage Go similaires, similaires aux annotations flexibles du framework Spring Cloud.
Grâce à trois années d'accumulation et d'exploration de directions, Swoft a fait de Swoft le Spring Cloud dans le monde PHP, qui est le meilleur choix pour le cadre hautes performances de PHP et la gestion des microservices.
Github
https://github.com/swoft-cloud/swoft
Article
Il s'agit d'un ensemble de didacticiels Swoft, qui seront mis à jour en permanence. Vous êtes invités à discuter et à apprendre ensemble.
Tutoriel
Installer
Utiliser Composer pour installer Swoft
swoft:/www# composer create-project swoft/swoft swoft Installing swoft/swoft (v2.0.5) - Installing swoft/swoft (v2.0.5): Loading from cache Created project in swoft > @php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 84 installs, 0 updates, 0 removals - Installing swoft/stdlib (v2.0.5): Loading from cache - Installing swoft/server (v2.0.5): Loading from cache - Installing nikic/php-parser (v4.2.4): Downloading (100%) ...... toolkit/cli-utils suggests installing inhere/php-validate (Very lightweight data validate tool) toolkit/cli-utils suggests installing inhere/console (a lightweight php console application library.) ...... Writing lock file Generating autoload files
Commencer
Après l'installation, accédez au répertoire racine du projet Swoft et démarrez Swoft comme ci-dessous.
root@MyServer:/tmp/swoft# php bin/swoft http:start 2019/09/14-10:29:34 [INFO] Swoft\SwoftApplication:setSystemAlias(485) Set alias @base=/tmp/swoft 2019/09/14-10:29:34 [INFO] Swoft\SwoftApplication:setSystemAlias(486) Set alias @app=@base/app ...... 2019/09/14-10:29:35 [INFO] Swoft\Processor\ConsoleProcessor:handle(39) Console command route registered (group 14, command 42) Information Panel *********************************************************************** * HTTP | Listen: 0.0.0.0:18306, type: TCP, mode: Process, worker: 3 * RPC | Listen: 0.0.0.0:18307, type: TCP *********************************************************************** HTTP server start success ! 2019/09/14-10:29:35 [INFO] Swoft\Server\Server:startSwoole(492) Swoole\Runtime::enableCoroutine 2019/09/14-10:29:35 [INFO] ......
Commencez le succès, vous pouvez voir le port hors Http et Rpc. Ensuite, vous accédez à l'adresse [ http://127.0.0.1:18306/ ] ( http : //127.0.0.1.118186/ ) dans le navigateur. La page suivante apparaîtra.

Bonjour tout le monde
Créez un nouveau fichier HelloWorldController.php
sous le répertoire du contrôleur Swoft (app / Http / Controller) comme ceci.
<?php declare(strict_types=1); namespace App\Http\Controller; use Swoft\Http\Server\Annotation\Mapping\Controller; use Swoft\Http\Server\Annotation\Mapping\RequestMapping; class HelloWorldController { public function index(): string { return 'Hello World !'; } }
Le contrôleur et le routeur utilisés ici seront décrits en détail dans l'article suivant, redémarrez le service, accès au navigateur [ http://127.0.0.1:18306/hello-world/index ] ( http://127.0.0.1:18306/ bonjour - Monde / index), vous obtiendrez la page suivante.

Banc
Testez simplement Swoft sous l'outil Apache Bench et les résultats sont les suivants:

Github
https://github.com/swoft-cloud/swoft