README.md 3.58 KB

How to use package

1) Add repository to composer.json

"repositories": [
  {
    "type": "vcs",
    "url": "git@gitlab.monotos.biz:pvduc/daito-utils.git"
  }
]

2) Install package

Stable (recommended - install by tag)

composer require daito/lib:^1.0

Dev (testing latest branch code)

composer require daito/lib:dev-master

3) Update package

Stable

composer update daito/lib

Dev branch

composer update daito/lib

Release by tag

After code is ready on release branch (for example production), create and push tag:

git tag v1.0.0
git push origin v1.0.0

Then projects using this package can update to the new stable version:

composer require daito/lib:^1.0
# or
composer update daito/lib

Performance note (DaitoMath)

DaitoMath uses brick/math for precise decimal calculations (financial-safe).

  • It can run without extra PHP extensions.
  • For better performance on production, enable one of:
    • ext-gmp (recommended)
    • ext-bcmath
  • brick/math will automatically use the fastest available calculator at runtime.

Quick check:

php -m | grep -Ei "gmp|bcmath"

Install extensions if missing:

# Ubuntu / Debian
sudo apt-get update
sudo apt-get install -y php-gmp php-bcmath
sudo systemctl restart php8.2-fpm || sudo systemctl restart apache2
# CentOS / RHEL / Rocky / AlmaLinux
sudo yum install -y php-gmp php-bcmath
sudo systemctl restart php-fpm || sudo systemctl restart httpd
# Windows (php.ini)
# 1) Open php.ini
# 2) Enable these lines:
extension=gmp
extension=bcmath
# 3) Restart web server / PHP-FPM service

QueryLog (Laravel shared package)

1) Publish config in child project

php artisan vendor:publish --tag=query-log-config

This creates config/query_log.php so each project can tune its own settings.

2) Publish migration in child project

php artisan vendor:publish --tag=query-log-migrations
php artisan migrate

This publishes a production-oriented migration for log_queries with key indexes:

  • query_at
  • query_type
  • connection
  • user_id
  • composite indexes for common filter windows

3) Minimal table fields

Use your own migration and ensure these columns exist in the configured table (query_log.table):

  • action (string)
  • query (longText/text)
  • query_type (string, example: insert, update, delete, replace)
  • query_time (float/double)
  • query_at (datetime)
  • query_order (int)
  • connection (string)
  • ip (nullable string)
  • user_id (nullable string/int)
  • is_screen (tinyint/bool)

4) Important config for production

  • enable: enable/disable query log
  • min_time: skip very fast queries (ms)
  • sample_rate: sampling percent (0-100) to reduce high-traffic load
  • chunk: batch size per queue job
  • max_queries_per_request: hard limit per request
  • skip_route_patterns: wildcard route/url patterns to skip
  • skip_command_patterns: wildcard console command patterns to skip
  • mask_sensitive_bindings: mask sensitive values in SQL bindings
  • sensitive_keywords: keyword list used for masking
  • masked_value: replacement text for sensitive bindings

5) Behavior highlights

  • Query buffer is separated by DB connection.
  • Buffer is flushed when transaction commits (outermost level).
  • Buffer is cleared on rollback (rolled-back queries are not logged).
  • Write-query detection supports CTE (WITH ... UPDATE/INSERT/...) and skips read queries.
  • query_type stores action text directly (insert, update, delete, replace, upsert).