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

Socket Laravel Package

react/socket

Async TCP/IP and TLS socket servers and clients for ReactPHP. Provides streaming, non-blocking connections built on EventLoop and Stream, with reusable interfaces and helpers for TCP, Unix sockets, secure servers, and connectors.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer: composer require react/socket. The SocketServer class is the primary entry point for building socket servers — pass a bound address like '127.0.0.1:8080' or '0.0.0.0:8080' to listen publicly. Use the connection event to handle incoming clients, receiving a ConnectionInterface instance that supports standard async streaming operations (write, end, close, pipe, and events like data, end, error, close). For clients, instantiate Connector and call connect('host:port') to get a promise resolving to a ConnectionInterface. Check the examples/ directory for minimal, working demos.

Implementation Patterns

  • Server with rate limiting: Wrap SocketServer in LimitingServer to restrict simultaneous connections, using getConnections() for introspection.
  • Security-first servers: Use SecureServer (or TLS URLs like tls://0.0.0.0:443) with stream_context_create() options for certificates.
  • Custom DNS resolution: Chain DnsConnector before TcpConnector in the Connector pipeline to enforce DNS validation or fallback.
  • Connection pooling / pipelining: Leverage ConnectionInterface’s pipe() to relay data streams (e.g., proxy servers), or use buffering strategies with ReadableStreamInterface / WritableStreamInterface interfaces.
  • Event loop integration: Use React’s EventLoop to schedule pauses/resumes (pause()/resume()) for traffic shaping or maintenance windows.
  • DNS-aware clients: Prefer HappyEyeBallsConnector for IPv4/IPv6 dual-stack fallback, and wrap with TimeoutConnector to avoid hanging on DNS resolution or connection delays.

Gotchas and Tips

  • IPv6 literals: Always wrap IPv6 addresses in square brackets ('[::1]:8080'); missing brackets cause InvalidArgumentException.
  • Port reuse: On Unix-like systems, set SO_REUSEADDR via stream_context_create(['socket' => ['so_reuseaddr' => true]]) and pass as context to avoid Address already in use errors during rapid restarts.
  • Error event ≠ fatal: The error event fires for non-fatal issues (e.g., failed connection attempts), not server shutdown — always attach handlers to avoid silent failures.
  • Context options: When constructing SocketServer or Connector, pass an optional stream_context to configure TLS (e.g., verify peers, SNI), bind to specific interfaces, or tweak timeouts.
  • Unix sockets: Paths must be absolute and prefixed with unix://; ensure the process has read/write permissions on the socket file/directory.
  • TLS certificate validation: By default, SecureConnector and SecureServer skip peer verification for dev safety. Always enable verification (verify_peer => true) in production and provide cafile or capath.
  • Typehinting: Accept ServerInterface/ConnectorInterface in your own APIs to enable easy mocking, swapping, and future upgrades (e.g., v3).
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport