Download the PHP package reinanhs/sqlcommenter-hyperf without Composer

On this page you can find all versions of the php package reinanhs/sqlcommenter-hyperf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sqlcommenter-hyperf

English | 中文

Sqlcommenter Logo

Stable Version Php Version Total Downloads Sqlcommenter License

Introduction

Sqlcommenter Hyperf is a library designed to automatically add comments to SQL queries executed by the Hyperf framework. These comments use the sqlcommenter format, which is understood by various database tools and services, providing enhanced insights and traceability for your application's database interactions.

Installation

You can install the library via Composer:

Add component configuration:

Sample

See an example of a simple query being executed:

Using this package, comments like this will be added:

By examining the above SQL statement and its comment in /*...*/, we can correlate and identify the fields in the SQL query to our source code in Hyperf:

Table 1: Information about the description of each type of comment

ORIGINAL FIELD INTERPRETATION
framework='Hyperf' The word “Hyperf” represents the framework that generated the query.
application='hyperf-skeleton' The name of the project where the code was run.
controller='UserController' Controller name in app/Controller.
action='index' Name of the method that was called called by the controller.
route='%%2Fapi%%2Ftest' The route used during the query call.
db_driver='mysql' The name of the Hyperf database engine.
traceparent='00-1cd60708968a61e942b5dacc2d4a5473-7534abe7ed36ce35-01' The W3C TraceContext Traceparent field of the OpenTelemetry trace.

Various tools and services can interpret these comments, helping to correlate user code with SQL statements generated by the ORM, and can be examined in the database server logs. This provides better observability into your application state up to the database server.

Here is an example of how this information appears within Google Cloud SQL:

The image above illustrates how sqlcommenter information is mapped within Google Cloud. In this context, sqlcommenter is being used to add tags in Query Insights, making it easier to identify which part of the application code is causing performance problems.

By clicking on one of these tags you will be able to view detailed information about the queries. See the example below:

In addition to Cloud SQL, several other tools also support sqlcommenter. One example is the Planetscale Query Insights.

Trace

By using the sqlcommenter-hyperf library, you can link Cloud SQL Query trace information with your Hyperf project. By synchronizing your information, you will achieve a much more detailed level of traceability than what is provided by Hyperf by default.

Below is a comparison between two images showing the trace information of the standard SQL in Hyperf and the trace from Cloud SQL Query:

The image below exemplifies the standard SQL trace in Hyperf:

The image below exemplifies the Cloud SQL trace associated with a request in Hyperf:

A tip when using the sqlcommenter-hyperf library is to disable the default SQL trace in Hyperf, as you will get more detailed information through the Cloud SQL Query trace in GCP.

Config

When you install the library in your project, it will be automatically enabled through the default settings. Therefore, to use this library, you only need to have it installed in your project.

However, if you want to disable some comments, you can do so through the settings. It is also worth mentioning that you can completely disable the execution of this library in a specific environment through the settings.

With the settings below, you can enable or disable the comments generated by this library. By default, all comments are enabled. You will find this configuration in the config/autoload/sqlcommenter.php file:

See below for a detailed explanation of each of the settings:

Setting Type Default Description
enable Boolean true Controls whether SQLCommenter is enabled or disabled. Set to true to enable SQLCommenter and add comments to SQL queries.
include.framework Boolean true Includes the name of the framework used in the SQL comments.
include.controller Boolean true Includes the name of the controller responsible for the action that generated the SQL query.
include.action Boolean true Includes the name of the action or method within the controller that generated the SQL query.
include.route Boolean true Includes the route associated with the request that generated the SQL query.
include.application Boolean true Includes the name of the application in the SQL comments.
include.db_driver Boolean true Includes the name of the database driver used to execute the SQL query.

Features

Performance

Using the Sqlcommenter Hyperf library may introduce a small performance impact due to the addition of comments to SQL queries. However, the benefits in terms of traceability, ease of debugging, and integration with monitoring tools generally outweigh this impact.

To demonstrate the effectiveness of the Sqlcommenter Hyperf library, we will conduct two distinct tests. The measurement will be performed in a controlled Google Cloud Run environment with the following configurations:

See below the project that was used as experiment:

Average execution time test of the code block:

In this test, we will measure the average execution time of the SqlCommenterAspect code block that adds SQL comments. After collecting 10,000 execution time records for this operation, we calculated the average execution time, which was approximately 0.103 milliseconds (ms).

This value indicates that inserting SQL comments into queries is an extremely fast operation, adding negligible overhead to the total query execution time.

Request latency performance test

In this test, we will use K6 to make multiple requests and compare the performance with the library enabled and disabled. See the results of this experiment below:

When analyzing the above image, we can see that initially, the response times are very similar for both configurations. However, as CPU consumption increases and we approach the limit of 1 vCPU, the disabled configuration (False) starts to perform slightly better. By examining the CPU utilization graphs, we observed that at around 400 VUs, CPU usage was approximately 98% for both configurations.

When the library is not competing intensely for CPU usage, it manages to maintain very good performance, close to that of the disabled configuration. This suggests that under high-demand conditions, the disabled configuration can handle the load slightly better, resulting in a marginal increase in the number of requests served per second.

If you want to check the detailed information about the test, it is recommended to click the link below:

Changelog

Please see CHANGELOG for more information about what has changed recently.

Contributing

Do you want to be part of this project? Read how to contribute.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

This project is under license. See the LICENSE file for more details.


All versions of sqlcommenter-hyperf with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
hyperf/config Version ~3.1.0
hyperf/database Version ~3.1.0
hyperf/db-connection Version ~3.1.0
hyperf/di Version ~3.1.0
hyperf/http-server Version ~3.1.0
hyperf/tracer Version ~3.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package reinanhs/sqlcommenter-hyperf contains the following files

Loading the files please wait ....