Download the PHP package microse/microse-swoole without Composer
On this page you can find all versions of the php package microse/microse-swoole. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download microse/microse-swoole
More information about microse/microse-swoole
Files in microse/microse-swoole
Package microse-swoole
Short Description Micro Remote Object Serving Engine based on swoole
License MIT
Homepage https://github.com/microse-rpc/microse-swoole
Informations about the package microse-swoole
🌹Microse
Microse (stands for Micro Remote Object Serving Engine) is a light-weight engine that provides applications the ability to serve modules as RPC services, whether in another process or in another machine.
This is the PHP version of the microse implementation based on Swoole. For API reference, please check the API documentation, or the Protocol Reference.
Other implementations:
- microse-node Node.js implementation
- microse-py python implementation
Install
Peel The Onion
In order to use microse, one must create a root ModuleProxyApp
instance, so
other files can use it as a root proxy and access its sub-modules.
Example
In other files, just define a class with the same name as the filename, so that
another file can access it directly via the $app
instance.
Don't forget to augment types in the AppInstance
class if you need IDE typing
support:
And other files can access to the module as a property:
Remote Service
The above example accesses the module and calls the function in the current process, but we can do more, we can serve the module as a remote service, and calls its functions as remote procedures.
Example
For example, if I want to serve a user service in a different process, I just have to do this:
Just try php server.php
and the services will be started immediately.
And in the client-side code, connect to the service before using remote functions.
NOTE: to ship a service in multiple server nodes, just create and connect to multiple channels, and register the service to each of them, when calling remote functions, microse will automatically calculate routes and redirect traffics to them.
NOTE: RPC calling will serialize (via JSON) all input and output data, those data that cannot be serialized will be lost during transmission.
Generator Support
When in the need of transferring large data, generator functions could be a great help, unlike general functions, which may block network traffic when transmitting large data since they send the data as a whole, generator functions, on the other hand, will transfer the data piece by piece.
The generator function returns an rpc version of the Generator, so if you want
to send data into the generator, you can use Generator::send()
to do so, the
value passed to the method will be delivered to the remote instance as well.
Life Cycle Support
Since swoole already handles asynchronous operations under the hood, so
lifecycle support is done by the original __construct
and __destruct
methods,
and there is no need for any extra efforts.
Standalone Client
Microse also provides a way to be running as a client-only application, in this case the client will not actually load any modules since there are no such files, instead, it just map the module names so you can use them as usual.
In the following example, we assume that $app->services->user
service is
served by a Node.js program, and we can use it in our PHP program as usual.
For client-only application, you may need to declare all abstract classes:
Process Interop
This implementation supports interop in the same process, that means, if it detects that the target remote instance is served in the current process, the function will always be called locally and prevent unnecessary network traffic.