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
Php Torcontrol

Php Torcontrol Laravel Package

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.

View on GitHub
Deep Wiki
Context7

PHP TorControl, a library to control TOR

Frequently asked questions about Php Torcontrol
How do I integrate php-torcontrol into a Laravel application for anonymized web scraping?
Register the `TorControl` client as a singleton in your `AppServiceProvider` using Laravel’s config-driven approach. Store Tor credentials in `.env` (e.g., `TOR_PASSWORD`) and inject the client into a service or job. Dispatch Tor commands asynchronously via Laravel queues to avoid blocking requests, especially for long-running tasks like scraping.
What Laravel versions and PHP versions does php-torcontrol officially support?
The package is tested on PHP 5–7/HHVM but may require polyfills or custom adapters for Laravel 10+ (PHP 8.1+). Test thoroughly with your Laravel version, as deprecated functions (e.g., `spl_object_hash`) could cause issues. Consider wrapping legacy code in compatibility layers if needed.
How can I securely store Tor authentication credentials in Laravel?
Use Laravel’s `.env` file to store sensitive credentials like `TOR_PASSWORD` or `TOR_COOKIE_AUTH_FILE`. Load these in `config/tor.php` and inject them into the `TorControl` constructor. Avoid hardcoding credentials in your application code to follow Laravel’s security best practices.
Does php-torcontrol support Tor Control Protocol v3, or is it limited to v2?
The library was last updated in 2016 and primarily supports Tor Control Protocol v2. For Tor v3 or newer, you may need to extend the package with custom command parsing or middleware to handle protocol differences. Test thoroughly with your Tor version to avoid compatibility issues.
How do I handle Tor connection drops or authentication failures in Laravel?
Use Laravel’s retry helper or custom middleware to handle transient failures. For example, wrap `TorControl::connect()` in a retry loop with exponential backoff. Log failures using Laravel’s logging system and consider emitting custom events (e.g., `TorConnectionFailed`) for reactive handling.
Can I use php-torcontrol with Dockerized Tor instances, and how do I configure UNIX sockets?
Yes, the library supports UNIX sockets. Configure the `TorControl` client with the socket path (e.g., `'socket' => '/var/run/tor/control.sock'`). Ensure your Docker container exposes the socket and grants PHP the correct permissions to access it. This is ideal for isolated Tor environments.
How do I mock Tor responses in PHPUnit tests for php-torcontrol?
Use Mockery or PHPUnit’s mock builder to create a mock `TorControl` instance. Stub methods like `executeCommand()` to return predefined responses. For integration tests, spin up a local Tor Docker container and configure it to respond to test commands, ensuring realistic behavior.
Is it better to use php-torcontrol or call Tor CLI tools directly via `exec()` in Laravel?
php-torcontrol provides a cleaner, object-oriented interface and better integration with Laravel’s ecosystem (e.g., dependency injection, queues). Calling Tor CLI via `exec()` is simpler but lacks abstraction and may introduce security risks (e.g., command injection). Use php-torcontrol for maintainability and Tor CLI only for quick scripts.
How can I extend php-torcontrol to emit Laravel events for Tor actions like NEWMYM?
Create custom events (e.g., `TorIdentityRenewed`) and dispatch them in your service layer after executing commands like `SIGNAL NEWMYM`. Use Laravel’s event system to listen for these events and trigger follow-up actions, such as logging or notifying other services.
What are the performance implications of blocking socket I/O in Laravel requests?
Blocking socket I/O can slow down synchronous Laravel requests. Mitigate this by offloading Tor commands to Laravel queues or using async libraries like ReactPHP. For example, dispatch `RenewTorIdentity` jobs to handle Tor operations in the background without impacting user requests.
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.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
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