swoole-suport-tars
General ideas
when server start,report alive.
Use the timer of the framework or swoole to report and survive every 30s. You can report in the worker or in the task (take note of swoole worker may be hung and the task is still there).
Write an entry file (such as index. PHP), according to the PHP service start stop script generated by the tars platform, and the conf configuration file issued by the tars platform, complete the configuration conversion (port number, number of workers) and start stop command control of the PHP framework.
For the HTTP service, the implementation of the above three steps can run in the tars. For other functions (see the introduction of the framework), you can introduce the composer extension of tarphp according to the actual situation.
For RPC Protocol services such as tars or Pb, it is necessary to package and unpack network protocol and business protocol (refer to tar sphp tcpserver). If custom code can be generated automatically, it will be better.
Take swoft as an example
edit composer.json,add phptars & deploy script。
Write a class for calling various interfaces of the tars platform (src/app/Tars/Manage.php)
When the framework is started successfully, the reporting service survives, which uses the event monitoring of swoft framework. (src/app/Listener/APPStart.php)
Report the survival every 30s. Here, use the swoft framework to annotate the trial timing task. (src/app/Tasks/TarsKeepAliveTask.php)
Write an entry file to control the start and stop of swoft framework. (src/index.php)
ps:Please refer to the following submission records https://github.com/dpp2009/swoftInTars/commit/97459b5012f9d7542a2a31d936c65ad8637ee1a0#diff-efc7d6cbd3cc43b894698099b51a99ab
Last updated