devture/symfony-web-command-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devture/symfony-web-command-bundle

Composer 安装命令:

composer require devture/symfony-web-command-bundle

包简介

Symfony bundle that allows console commands to be called from the web in a secure manner

README 文档

README

A Symfony bundle that lets you execute your application's console commands from the web in a secure manner.

This is useful in environments where you can't run your console commands directly (from cron, etc.), but you can access the application from the web. It can let you convert cronjobs from something like this:

* * * * * user php /app/bin/console ticket:purge

to:

* * * * * user curl -sS -XPOST -H 'Authorization: Bearer SECRET' http://application/web-command/execute/ticket:purge

Installation

Install through composer (composer require devture/symfony-web-command-bundle:dev-master).

Add to config/bundles.php:

Devture\Bundle\WebCommandBundle\DevtureWebCommandBundle::class => ['all' => true],

Configuration

Drop the following routing config in config/packages/devture_web_command.yaml

devture_web_command:
  auth_token: '%env(DEVTURE_WEB_COMMAND_AUTH_TOKEN)%'
  forced_uri: '%env(DEVTURE_WEB_COMMAND_FORCED_URI)%'

The environment variable DEVTURE_WEB_COMMAND_AUTH_TOKEN would contain your authentication secret. Make it a strong one (e.g. by using pwgen -Bsv1 64).

The environment variable DEVTURE_WEB_COMMAND_FORCED_URI contains the external URL to your application, so that "console commands" invoked locally (curl http://localhost/web-command/...) would still generate the correct full URLs. Example value: https://example.com. It can also be left blank (empty string) to avoid force-setting and rely on auto-detection.

Routing

Drop the following routing config in config/routes/DevtureWebCommandBundle.yaml:

DevtureWebCommandBundleWebsite:
    prefix: /web-command
    resource: "@DevtureWebCommandBundle/Resources/config/routes/website.yaml"

Security

If using Symfony's Security component to Secure URL patterns, you may wish to adjust the firewall to not block /web-command requests.

Modify: config/packages/security.yaml:

security:
  # Other stuff..

  access_control:
    # Other stuff..
    - { path: ^/web-command/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    # Other stuff..
    - { path: ^/, role: ROLE_USER }

Usage

Execute commands from the web by making a POST request to the /web-command/execute/:commandName route.

You need to authenticate using the authentication token provided to the bundle (usually stored in the DEVTURE_WEB_COMMAND_AUTH_TOKEN environment variable).

The basic call would be something like this (using cURL for this example):

curl \
-sS \
-XPOST \
-H 'Authorization: Bearer SECRET' \
http://application/web-command/execute/commandName

You can POST a JSON payload to this URL endpoint to configure it. Example:

# outputVerbosity = 256 means "debug". See the `OutputInterface:VERBOSITY_` constants.

curl \
-sS \
-XPOST \
-H 'Authorization: Bearer SECRET' \
--data '{"input": {"days": 10, "--something": 4}, "outputVerbosity": 256}' \
http://application/web-command/execute/ticket:purge

devture/symfony-web-command-bundle 适用场景与选型建议

devture/symfony-web-command-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 458 次下载、GitHub Stars 达 7, 最近一次更新时间为 2019 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「bundle」 「console」 「cron」 「command」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 devture/symfony-web-command-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 devture/symfony-web-command-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 devture/symfony-web-command-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 458
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-06-10