定制 szczyglis/php-ultra-small-proxy 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

szczyglis/php-ultra-small-proxy

Composer 安装命令:

composer require szczyglis/php-ultra-small-proxy

包简介

Lightweight proxy with full support for sessions, cookies, POST/FORM submissions, and URL rewriting.

README 文档

README

Release: 2.1.3 | build: 2024.08.26 | PHP: ^7.2.5|^8.0

Ultra Small Proxy 2

Ultra Small Proxy is a lightweight proxy written in PHP.

How to install

composer require szczyglis/php-ultra-small-proxy

Features

  • Proxy server written in PHP
  • Easy to use and integrate
  • Simple and lightweight
  • Sessions support
  • Supports sending and receiving cookies
  • Supports sending and receiving HTTP headers
  • Cache and asset storage
  • Domain and IP/host connection support
  • HTTP Basic Auth support
  • GET and POST request handling
  • Form submission support
  • POST variable redirection
  • Toolbar with address bar, configuration, and debugger
  • URLs rewritten/proxied at runtime (links, images, CSS, JavaScript, etc.)
  • Two different methods for URL rewriting: Regex (with preg_replace) and XML (with libxml/DOM)
  • Supports PHP 7.2.5+ and 8.0+

Requirements

Usage example

<?php
// app.php

require __DIR__ . '/vendor/autoload.php';

use Szczyglis\UltraSmallProxy\UltraSmallProxy;
use Szczyglis\UltraSmallProxy\Config;

$config = new Config();

$proxy = new UltraSmallProxy($config);

echo $proxy->load('https://github.com'); // <-- specify start page here

Ensure you have write permissions to the ./cookies and ./cache directories.

WARNING: The cookies directory should not be publicly accessible!

Screenshot

proxy

Open loopback.php if you want to test proxy features such as session support, POST variable redirection, form submission, and more, e.g.:

<?php

$output = $proxy->load('http://localhost/loopback.php'); 

Repository contents:

  • src/ - proxy classes

  • index.php - usage example

  • loopback.php - loopback for testing features like session support, form variable sending, and cookie redirection

Basic usage

use Szczyglis\UltraSmallProxy\UltraSmallProxy;
use Szczyglis\UltraSmallProxy\Config;

$config = new Config();
$proxy = new UltraSmallProxy($config);

echo $proxy->load('https://github.com');

Configuration

$output = $proxy->load('https://github.com', $force = false); 

Boolean $force - if set to false, URLs given in the QUERY STRING will always overwrite URLs passed here. Set to true to reverse this behavior. Default: false.

Config values:

Before page load:

$config->set('init', true) - boolean, auto-init true|false, default: true

$config->set('source', 'domain') - string, input source domain|ip, default: domain

$config->set('raw', false) - boolean, raw download true|false, default: false

$config->set('toolbar', true) - boolean, attach toolbar true|false, default: true

$config->set('user_agent', 'Mozilla/4.0 (compatible;)') - string, user agent, default: Mozilla/4.0 (compatible;)

$config->set('timeout', 120) - int, curl timeout, default: 120

$config->set('max_redirects', 10) - int, curl max redirects, default: 10

$config->set('cookies_dir', './cookies') - string, cookies directory, default: ./cookies

$config->set('cache_dir', './cache') - string, cache directory, default: ./cache

$config->set('method', 'GET') - string, request method GET|POST

$config->set('rewrite', 'REGEX2') - string, rewrite method REGEX,REGEX2,REGEX3,DOM, default: REGEX2

$config->set('rewrite_url', true) - boolean, enable URL rewriting true|false, default: true

$config->set('rewrite_img', true) - boolean, enable IMG rewriting true|false, default: true

$config->set('rewrite_js', true) - boolean, enable JS rewriting true|false, default: true

$config->set('rewrite_form', true) - boolean, enable FORM ACTION rewriting true|false, default: true

$config->set('rewrite_css', true) - boolean, enable CSS rewriting true|false, default: true

$config->set('rewrite_video', true) - boolean, enable VIDEO rewriting true|false, default: true

$config->set('rewrite_ip', true) - boolean, enable domain to IP+Host resolve true|false, default: true

$config->set('assets', 'REDIRECT') - string, assets proxying mode REDIRECT|CURL, default: REDIRECT

$config->set('is_cfg', false) - boolean, show options true|false, default: false

$config->set('is_dbg', false) - boolean, show debug true|false, default: false

$config->set('htaccess_user', 'user') - string, HTTP AUTH user

$config->set('htaccess_pass', 'pass') - string, HTTP AUTH password

Public methods

After page load:

$siteCookies = $proxy->cookie->getSiteCookies() - returns cookies[] received from proxied site

$localCookies = $proxy->cookie->getLocalCookies() - returns cookies[] stored localy and sended to proxied site

$status = $proxy->http->getStatus() - returns connection status[]

$headers = $proxy->http->getHeaders() - returns received headers[]

$sid = $proxy->getSid() - returns proxied PHPSESSID if exists

$errors = $proxy->getErrors() - returns error messages[] if occured

Other methods:

$parsed = $proxy->render($html) - parses/rewrites URLs in custom HTML content with the selected $rewriteMode.

Changelog

2.1.0 -- Package was added to Packagist (2022-04-23)

2.1.1 -- Updated PHPDoc (2022-04-25)

2.1.2 -- Updated composer.json (2022-04-28)

2.1.3 -- improved documentation (2024-08-26)

Ultra Small Proxy is free to use, but if you like it, you can support my work by buying me a coffee ;)

https://www.buymeacoffee.com/szczyglis

Enjoy!

MIT License | 2022 Marcin 'szczyglis' Szczygliński

https://github.com/szczyglis-dev/php-ultra-small-proxy

https://szczyglis.dev

Contact: szczyglis@protonmail.com

szczyglis/php-ultra-small-proxy 适用场景与选型建议

szczyglis/php-ultra-small-proxy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 258 次下载、GitHub Stars 达 20, 最近一次更新时间为 2022 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 szczyglis/php-ultra-small-proxy 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 258
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-23