phrity/net-stream
PSR-7 StreamInterface and PSR-17 StreamFactory implementations built for socket-based I/O. Includes Stream, SocketStream, SocketClient/Server, context wrapper, stream collections, and stream-specific exceptions and utilities for network connections.
Illuminate\Http\StreamedResponse, GuzzleHttp\Psr7\Stream, and Laravel’s service container. This allows for unified stream handling across HTTP and socket-based operations.SocketClient, SocketServer, and SocketStream extends Laravel’s capabilities to raw TCP/UDP sockets, enabling use cases like:
Context class and listener system (e.g., onConnect, onFailure) provide hooks for custom logic, such as:
StreamCollection enables efficient management of multiple connections, which is critical for:
StreamFactory can replace or extend Laravel’s default implementations (e.g., Symfony\Component\HttpFoundation\StreamedResponse or GuzzleHttp\Psr7\Stream).// config/app.php
'stream_factory' => Phrity\Net\StreamFactory::class,
Phrity\Net\Stream for both HTTP and socket-based streams, reducing duplication.SocketClient/SocketServer for consistency.Socket facade to abstract socket operations:
Socket::client('tcp://example.com:1234')->connect();
StreamCollection and SocketStream methods (e.g., closeRead(), closeWrite()) enable asynchronous I/O patterns compatible with Laravel’s middleware pipeline.SocketClient can be used in Laravel’s queue workers for outbound network operations (e.g., sending data to external systems).hasContents()) are critical for your use case.Stream::detach() or SocketStream::close() could lead to resource leaks (e.g., open file descriptors).__destruct cleanup).Illuminate\Support\Manager to centralize stream lifecycle management.spatie/laravel-async or reactphp/reactphp-src).StreamException should be mapped to Laravel’s ExceptionHandler for consistent logging/errors.StreamException into Laravel’s error format.Illuminate\Http\Client or manual stream_context_create() will be required.HttpClient for TLS-secured sockets or implement a Context listener for SSL context setup.react/socket, ratchet) or augment them?Swoole or ReactPHP for high-scale scenarios?HttpClient or require custom stream_context_create() logic?SocketClient as a singleton)?StreamCollection scale under high concurrency (e.g., thousands of simultaneous connections)?StreamFactory to use Phrity\Net\StreamFactory. This enables PSR-7/PSR-17 compliance across both HTTP and socket streams.
$this->app->bind(\Psr\Http\Message\StreamFactoryInterface::class, \Phrity\Net\StreamFactory::class);
SocketStream for custom streaming logic in Laravel’s StreamedResponse or API endpoints.SocketStream methods (e.g., closeRead(), hasContents()) in middleware for real-time data processing.SocketClient and SocketServer:
// app/Providers/SocketServiceProvider.php
public function register()
{
$this->app->singleton('socket.client', function () {
return new \Phrity\Net\SocketClient();
});
}
SocketClient into controllers or jobs.SocketStream in an event loop.react/socket alongside Phrity\Net\Stream for async socket handling.SocketClient in Laravel’s queue workers for outbound network tasks (e.g., sending data to external APIs or IoT devices).use Phrity\Net\SocketClient;
class SendDataToDeviceJob implements ShouldQueue
{
public function handle()
{
$socket = new SocketClient();
$socket->connect('tcp://device.example.com:5000');
$socket->write('data');
}
}
StreamFactory with Phrity\Net\StreamFactory.Socket facade or service provider to wrap SocketClient/SocketServer.stream_socket_client) with the package’s abstractions.Context listeners for custom logic (e.g., authentication, logging).StreamCollection for managing multiple connections (e.g., in real-time systems or background workers).How can I help you explore Laravel packages today?