PHP microservices framework — Swoft 2.0.5 published
Tags: php
Published: 2019-08-08 13:16:28

## What is Swoft?

Swoft is a PHP microservices coroutine framework based on the Swoole extension. Like Go, Swoft has a built-in coroutine web server and a common coroutine client and is resident in memory, independent of traditional PHP-FPM. There are similar Go language operations, similar to the Spring Cloud framework flexible annotations, powerful global dependency injection container, comprehensive service governance, flexible and powerful AOP, standard PSR specification implementation and so on.


Through three years of accumulation and direction exploration, Swoft has made Swoft the Spring Cloud in the PHP world, which is the best choice for PHP's high-performance framework and microservices management.

## Efficient seconds crontab

The following simple lines of code define a timed task that is executed every second, which can completely replace the system crontab.

```
<?php declare(strict_types=1);

namespace App\Crontab;

use Swoft\Crontab\Annotaion\Mapping\Cron;
use Swoft\Crontab\Annotaion\Mapping\Scheduled;

/**
 * Class CronTask
 *
 * @since 2.0
 *
 * @Scheduled()
 */
class CronTask
{
    /**
     * @Cron("* * * * * *")
     */
    public function secondTask()
    {
        printf("second task run: %s ", date('Y-m-d H:i:s', time()));
    }
}
```
The crontab starts with the service and will see the following display:

![-w1249](https://habrastorage.org/webt/ta/ag/1h/taag1h3rpqrxtv8nqgkhvt0q6ti.jpeg)


## Exception management

During the development process, if the error message is a string of characters, it is not convenient for the business to solve the problem. If the component is used, all error messages will be displayed as follows:

![whoops](https://habrastorage.org/webt/rs/6c/qy/rs6cqyiok1gkruxsvajjamjqxvm.png)

## Update

Fixed：

- Fixing early interrupt request logic may result in incorrect formatting of the corresponding Content-Type [f031398](https://github.com/swoft-cloud/swoft-component/pull/493/commits/f03139886a471a0424d236061e8cb30d90b32a89)
- Fixed the use of sgo to create child coroutines, at the end did not clean up the mapping with the top coroutine [de11ae5b](https://github.com/swoft-cloud/swoft-component/pull/493/commits/de11ae5bc63833b80ca491132d156d51b95f6c8d)
- Fix Xml format parsing method [24d0038](https://github.com/swoft-cloud/swoft-component/pull/495/commits/24d0038dc644fccf238d9642f049ceb961dd22b3)
- Fix class proxy Unique string problem [444ddeb](https://github.com/swoft-cloud/swoft-component/pull/495/commits/444ddeb51e0741dda06e8f548f2579cf534bdf30)
- Fixed `context()->get()` problem and discard `Context::mustGet()` method [6acc1b5](https://github.com/swoft-cloud/swoft-component/pull/496/commits/6acc1b55163a18edc95de6cdb899398a9a7d0f2e)
- Fixed interface injection, class name access error [2d9a31f](https://github.com/swoft-cloud/swoft-component/pull/496/commits/2d9a31fe1855054055daa6e6e73aeaddfa280900)
- Repair model uses the `paginate` method, the result set has no mapping field [3027287](https://github.com/swoft-cloud/swoft-component/commit/3027287a58bfa66b3c87b8d2d03fddbfc6c2c754)
- Fixed websocket server error when there are multiple workers and actively closes non-current worker connections [7666969](https://github.com/swoft-cloud/swoft-component/pull/500/commits/7666969f731dce68d395f45749260731eead7bda)


Update:

- The default worker num setting is obtained by the `swoole_cpu_num` function [553f6500](https://github.com/swoft-cloud/swoft-component/pull/493/commits/553f6500678b258080b84cffeab0fe2d5bf65550)
- The validator is adjusted to, the default is not required, the user opens [e5b258d](https://github.com/swoft-cloud/swoft-component/pull/496/commits/e5b258db35683e50f4abeba22a2c6fa82dbc7ceb)
- No longer throws `containerException` inside the swowt to the user-used layer [1e74893](https://github.com/swoft-cloud/swoft-component/pull/498/commits/1e74893bf6e05fe954334e527e8b76eca2cef6e9)
- console output Add interactive methods such as `confirm` `select` [0181138a](https://github.com/swoft-cloud/swoft-component/pull/498/commits/0181138af6f1bc1dc0f3f1025b23d9a6354d122a)


Enhancement：

- The console command option sets `CommandOption`, which now allows options to be described as multiple lines of information [e5914983](https://github.com/swoft-cloud/swoft-component/pull/493/commits/e591498363dac1888f503ab18766e89542e33665)
- All messaging methods for websocket server, support for incoming `opcode` parameter [dc164ffe9](https://github.com/swoft-cloud/swoft-component/pull/493/commits/dc164ffe97d507e505ac8cd1b50a421a27ae5859)
- The websocket module allows setting the default `opcode` of the current module for automatic processing of return data settings `opcode` [9e3e9672](https://github.com/swoft-cloud/swoft-component/pull/493/commits/9e3e9672ed83579e6135ed47ae0c30ef335d8659 )
- Enhanced websocket related classes, now the message processing method allows to inject more data object types `Request` `Response` [3d6c60b4](https://github.com/swoft-cloud/swoft-component/pull/493/commits/3d6c60b4812535c48d51c57476f801529f66655f )
- When the worker exits, the websocket server will automatically close all connections [5ea10ecc](https://github.com/swoft-cloud/swoft-component/pull/498/commits/5ea10ecc4bcf767b374dad9652dd57a4fcfc8fc5)
- Add Timer timer package [eb92ee6](https://github.com/swoft-cloud/swoft-component/pull/495/commits/eb92ee6a7d5e7f2a47e30920a83ed192626b42e3)
- Add Coroutine Method Package [d8c2b88](https://github.com/swoft-cloud/swoft-component/pull/495/commits/d8c2b8848d492fc4b389df6edee595ef8f0e39c5)


## Resource
- GitHub: [https://github.com/swoft-cloud/swoft](https://github.com/swoft-cloud/swoft)