dunglas/php-torcontrol
PHP TorControl is a lightweight library to control a Tor server via the Tor Control Protocol. Connect over TCP/SSL/UNIX sockets, authenticate via null/password/cookie, send commands (e.g., NEWNYM), and handle multi-line replies. Composer install.
executeCommand()) integrates cleanly with Laravel’s service containers and queues (e.g., dispatching Tor commands as jobs)..env files).DunglasTorControlBundle provides a Symfony/Laravel-friendly facade (e.g., dependency injection, configuration via config/services.php).TorControlConnected, TorIdentityRenewed) for reactive workflows.spl_object_hash).config('tor.password')).NEWMYNM) could trigger DoS risks if misused. Requires Laravel middleware to throttle.retry helper or a custom TorControlException).Mockery or a local Tor Docker container.)tor --control-port) via exec() or a Go/Rust wrapper for better maintenance?Laravel Ecosystem:
TorControl client as a singleton in AppServiceProvider:
$this->app->singleton(TorControl::class, function ($app) {
return new TorControl([
'hostname' => config('tor.host'),
'port' => config('tor.port'),
'password' => config('tor.password'),
'authmethod' => TorControl::AUTH_PASSWORD,
]);
});
config/tor.php:
'connections' => [
'default' => [
'host' => env('TOR_HOST', 'localhost'),
'port' => env('TOR_PORT', 9051),
'auth' => 'password', // or 'cookie'
'password' => env('TOR_PASSWORD'),
'cookie' => env('TOR_COOKIE_AUTH_FILE'),
],
],
TorControl facade for cleaner syntax:
use Illuminate\Support\Facades\Facade;
class TorControl extends Facade { protected static function getFacadeAccessor() { return 'tor'; } }
Usage: TorControl::renewIdentity().Queue Integration:
class RenewTorIdentity implements ShouldQueue
{
public function handle(TorControl $torControl) {
$torControl->executeCommand('SIGNAL NEWNYM');
}
}
Phase 1: Proof of Concept
NEWMYNM, GETINFO).TorControlException for failed connections).Phase 2: Laravel Wrapper
laravel-tor-control) to:
TorConnected, TorCommandFailed).Phase 3: Production Rollout
tor:latest image) for isolation.circuit-breaker package) for Tor failures.php-sockets). Ensure it’s enabled in php.ini.tor --control-port 9051)..env with Tor credentials.spl_object_hash deprecation).config/ to avoid hardcoding.Log notice stdout in Tor config (torrc) for debugging.Log::debug().chmod 600).NEWMYNM, GETINFO status/networkstatus).552 for invalid commands).TorControl instances (singleton) to avoid TCP overhead.NEWMYNM) to test Tor’s MaxMemInQueue limits.How can I help you explore Laravel packages today?