
Last time we talked about
layered architecture in the yii framework, and now we want to share the code.
In our work, we actively use open source solutions, and therefore we decided to share our own developments that can be useful to the community. Today, these are extensions for probably the world's best PHP framework
yii :
- DGSphinxSearch
- AMQP (RabbitMQ)
- MQLogRouter
- DGPinbaLogRoute
- DGApiClient
Consider these extensions in order.
')
DGSphinxSearch
Sphinx is a high-performance, full-text search engine that you probably know well. The extension allows you to implement both procedural and object-oriented approach to the formation of queries and work with data. The extension is fully integrated into yii and allows you to monitor your work using standard framework tools. To work on servers where C ++ is not installed - an extension for PHP, the mode of operation through a script library is supported.
For example, let's try to find no more than 30 entries among users named Vasily:
$userlist = Yii::App()->sphinx->select('name')->from('users')->where('')->limit(0, 30)->search();
It has become significantly smaller than when using the original library for Sphinx.
Details are on the extension page on the yii website:
www.yiiframework.com/extension/dgsphinxsearchAMQP
RabbitMQ is a fast messaging server written in the Erlang fault-tolerant language.
The extension simplifies not only with RabbitMQ, but also with any MQ servers that support the AMQP protocol, and allows you to send and receive messages from the server, and also supports debugging mode of operation when there is no direct connection to the server.
To send a message to the outbox, we do:
Yii::App()->rabbitMQ->exchange('outbox')->publish('!', '');
To receive a message from the inbox queue, which is subscribed to the outbox, we do:
Yii::App()->rabbitMQ->queue('inbox')->get();
Extension page:
www.yiiframework.com/extension/amqpMQLogRouter
A very convenient logging and profiling system is built into yii. In the base delivery, it allows you to save logs to the file system, to the database, or output to the browser. We added a special LogRoute, which sends logs to the MQ server.
The convenience of the solution is manifested when there is a need to analyze the interaction of several separate applications interacting through REST or SOAP interface and leading logs on different servers.
www.yiiframework.com/extension/cmqlogroute - the connection instruction is quite simple and comes down to configuring the application config.
DGPinbaLogRoute
Pinba is a server monitoring and code profiling tool. Due to the fact that the packets to the server are sent asynchronously, the transfer does not affect the performance of your application. Pinba itself collects summary statistics on the execution of each script and allows it to be used in real time.
To send logs to Pinba, it is enough to connect DGPinbaLogRoute as a yii-logger and call the usual ones for yii:
Yii::beginProfile(); …..; Yii::endProfile();
Learn more here:
www.yiiframework.com/extension/dgpinbalogrouteWe see the next step in the visualization of the collected statistics and plan to share the corresponding module.
DGApiClient
APIClient is a PHP wrapper for our
API 2GIS product. The product itself allows applications to receive 2GIS reference data for more than 1 million organizations and create local search services on their basis or use them on already existing city portals, thematic sites and other projects.
The extension facilitates integration tasks and allows the developer to abstract from the implementation of REST requests and work with the API directly from PHP code. Consider an example of how to use it.
For example, here we get a list of 10 geo-objects 100 meters from the point 82.901886,54.991984 in the xml-format:
$list = Yii::App()->apiClient->geoSearch(array( 'q' => '82.901886,54.991984', 'radius' => 100, 'limit' => 10, ), 'xml');
And now we are looking for 10 companies for the request "beer" in the vicinity of the Arbat in Moscow:
$list = Yii::App()->apiClient->search(array( 'where' => ' ', 'what' => '', 'limit' => 10, ), 'xml');
If we want to receive the answer in the form of objects, it is enough to replace 'xml' with 'object'.
The full list of methods is given in the API documentation on
api.2gis.ru* * *
A complete list of yii extensions that our development teams post can be found on the framework's framework for the 2GIS tag:
www.yiiframework.com/extensions/?tag=2GISOf course, this is not all that we would like to share. In the future, we plan to lay out an extension for ActiveRecord, which can work with several database servers at the same time, and a task manager, which allows you to run various tasks, controlling their order and number. If the applications described are in demand, we will continue to make our small contribution to the large and important Open Source movement.