Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Socks React Laravel Package

clue/socks-react

Async SOCKS5/SOCKS4(a) proxy client and server for ReactPHP. Tunnel any TCP/IP protocol (HTTP, SMTP, IMAP, etc.) through a SOCKS proxy using the standard ConnectorInterface, enabling easy drop-in proxy support and parallel connections.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Async-first design: Aligns perfectly with Laravel’s growing adoption of async/await (via Symfony’s psr/http-client-implementation and ReactPHP integration). The package’s ReactPHP foundation ensures non-blocking I/O, critical for high-throughput proxy routing.
  • Protocol-agnostic: Supports TCP, TLS, and HTTP(S) out of the box, making it versatile for Laravel’s HTTP clients (e.g., Guzzle, Symfony HTTP Client) or custom TCP-based services (e.g., WebSockets, SMTP).
  • ConnectorInterface compliance: Drop-in replacement for ReactPHP’s Connector, enabling seamless integration with existing async stacks (e.g., react/http, react/socket).

Integration Feasibility

  • Laravel HTTP Clients:
    • Guzzle: Requires wrapping the SOCKS client in a GuzzleHttp\HandlerStack with a custom SocksHandler. Feasible but adds complexity.
    • Symfony HTTP Client: Native support via HttpClient::withOptions(['proxy' => 'socks://...']) (PHP 8.1+). Prefer this for simplicity.
    • Custom TCP Services: Directly use the Client with React\Socket\ConnectionInterface for low-level protocols (e.g., SMTP, Redis).
  • Laravel Queues: Async job execution through SOCKS proxies is possible but requires custom queue drivers (e.g., react/async-queue + SOCKS-wrapped connections).

Technical Risk

  • Blocking vs. Async: Laravel’s core (e.g., Eloquent, Blade) is synchronous. Mixing sync/async code risks deadlocks or performance bottlenecks. Mitigate by:
    • Isolating async logic to dedicated services (e.g., ProxyService).
    • Using Spatie\Async or Laravel Horizon for async job orchestration.
  • Dependency Bloat: ReactPHP adds ~10MB to Laravel’s footprint. Justify with:
    • Feature flags for proxy-enabled routes/services.
    • Lazy-loading the package (e.g., via service provider checks).
  • Protocol Limitations:
    • No UDP support (critical for DNS-over-SOCKS or VoIP).
    • SOCKS4 lacks IPv6/authentication (restrict to SOCKS5 where possible).

Key Questions

  1. Use Case Priority:
    • Is this for HTTP(S) proxying (low risk) or custom TCP protocols (higher risk)?
    • Does the team have ReactPHP experience, or will training be needed?
  2. Proxy Infrastructure:
    • Are SOCKS servers internal (e.g., SSH tunnels) or third-party (e.g., commercial proxies)? The latter may introduce latency/jitter.
  3. Fallback Strategy:
    • How will direct connections bypass proxies when needed (e.g., for local services)?
  4. Monitoring:
    • How will connection timeouts/errors be logged (e.g., Sentry, Laravel Log)?
  5. Testing:
    • Are there existing SOCKS servers for CI/CD testing, or will mocks be needed?

Integration Approach

Stack Fit

Laravel Component Integration Strategy Tools/Libraries
HTTP Clients (Guzzle/Symfony) Replace default connector with SOCKS-wrapped Connector or use Symfony’s proxy option. clue/socks-react, symfony/http-client
Queues Custom queue driver using React\AsyncQueue + SOCKS connections. react/async-queue, illuminate/queue
TCP Services Direct Client usage with React\Socket\ConnectionInterface. clue/socks-react, react/socket
Artisan Commands Async command handlers with SOCKS support (e.g., php artisan proxy:fetch). laravel/framework, clue/socks-react
Event Listeners Async listeners using React\EventLoop (advanced). react/event-loop, laravel/events

Migration Path

  1. Phase 1: HTTP Proxying (Low Risk)

    • Replace GuzzleHttp\Client with Symfony\HttpClient (PHP 8.1+).
    • Configure proxy via HttpClient::withOptions(['proxy' => 'socks://user:pass@host:port']).
    • Test with curl --socks5-hostname to validate behavior.
    • Tools: symfony/http-client, phpunit.
  2. Phase 2: Async TCP Services (Medium Risk)

    • Create a ProxyConnector service wrapping Clue\React\Socks\Client.
    • Example:
      $connector = new React\Socket\Connector([
          'tcp' => new Clue\React\Socks\Client('socks5://proxy:1080'),
          'dns' => false,
      ]);
      
    • Integrate with React\AsyncQueue for async jobs.
    • Tools: reactphp/react, spatie/async.
  3. Phase 3: Full Async Stack (High Risk)

    • Replace Laravel’s event loop with React\EventLoop.
    • Use Laravel React packages (e.g., laravel-react/queue) for async queues.
    • Tools: laravel-react/queue, reactphp/promise.

Compatibility

  • Laravel Versions:
    • LTS (10.x/11.x): Use Symfony HTTP Client (PHP 8.1+) or Guzzle 7+ with custom middleware.
    • Older (8.x): Guzzle 6.x requires manual SocksHandler implementation.
  • PHP Versions:
    • PHP 8.1+: Preferred (Symfony HTTP Client, named arguments).
    • PHP 7.4: Works but lacks some features (e.g., socks5:// URI parsing).
  • Existing Proxies:
    • Test with SOCKS5 (recommended) and SOCKS4(a) if legacy support is needed.
    • Validate authentication methods (e.g., user:pass@host).

Sequencing

  1. Proof of Concept:
    • Implement a single route/service with SOCKS proxying (e.g., Route::get('/proxy-test', ...)).
    • Use Symfony\HttpClient for simplicity.
  2. Feature Flags:
    • Enable proxying via config (e.g., config/proxy.php).
    • Example:
      'enabled' => env('USE_SOCKS_PROXY', false),
      'host' => env('SOCKS_HOST', '127.0.0.1'),
      'port' => env('SOCKS_PORT', 1080),
      
  3. Gradual Rollout:
    • Start with non-critical services (e.g., web scraping, external APIs).
    • Monitor latency/errors before applying to core workflows.
  4. Fallback Mechanism:
    • Implement a ProxyService with direct connection fallback:
      public function connect(string $uri): ConnectionInterface {
          try {
              return $this->socksClient->connect($uri);
          } catch (Exception $e) {
              return $this->directConnector->connect($uri);
          }
      }
      

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor clue/socks-react and reactphp/react for breaking changes.
    • Pin versions in composer.json to avoid surprises (e.g., ^1.0).
  • Configuration Drift:
    • Centralize proxy settings in config/proxy.php to avoid hardcoded values.
    • Use Laravel’s env() for runtime overrides.
  • Logging:
    • Log SOCKS connection metadata (e.g., proxy host, latency, errors) for debugging.
    • Example:
      \Log::debug('SOCKS connection', [
          'proxy' => $proxy->getUri(),
          'target' => $uri,
          'duration_ms' => $stopwatch->duration(),
      ]);
      

Support

  • Troubleshooting:
    • Common issues:
      • Timeouts: Adjust connect_timeout in Connector options.
      • Authentication: Ensure credentials are passed via URI (socks5://user:pass@host).
      • DNS Leaks: Disable DNS resolution in the proxy ('dns' => false).
    • Debugging tools:
      • tcpdump to inspect SOCKS traffic.
      • socks-proxy-cli to test proxy connectivity.
  • Documentation:
    • Add a proxy.md to the Laravel app’s docs with:
      • Setup instructions.
      • Example configurations.
      • Known limitations (e.g., no UDP).

Scaling

  • Horizontal Scaling:
    • SOCKS proxies are connection-bound. Scale by:
      • Using a proxy pool (e.g., round-robin across multiple SOCKS servers).
      • Implementing connection
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core